Reputation: 287
I want to use SkyDrive to backup some information.
But seems they have removed this namespace Microsoft.Live.Controls;
from the new SDK, and all code samples and also answers here are outdated.
this reference also is outdated; there is no more LiveConnectClient
How can I simply backup files to SkyDrive after these changes?
(any code sample or reference is appreciated.)
Upvotes: 3
Views: 4564
Reputation: 14318
It's not that hard, but there really are no references or tutorials. Everything that's below works just fine in my Windows Phone 8 project.
You need to include Microsoft.Live
namespace after installing Live SDK.
First you have to create and initialize the client. After that, you log in and can send over some data:
LiveConnectClient client;
var auth = new LiveAuthClient("YourGeneratedKey");
var result = await auth.InitializeAsync(new [] {"wl.basic", "wl.signin", "wl.skydrive_update" });
// If you're not connected yet, that means you'll have to log in.
if(result.Status != LiveConnectSessionStatus.Connected)
{
// This will automatically show the login screen
result = await auth.LoginAsync(new [] {"wl.basic", "wl.signin", "wl.skydrive_update" });
}
if(result.Status == LiveConnectSessionStatus.Connected)
{
client = new LiveConnectClient(result.Session);
}
Maybe the process above could be simplified, but it works for me.
Now you can use the client if everything went as planned. I've managed to successfully upload files from streams.
Let's say you've obtained a Stream
to the file you want to send (I got that via WinRT file API on Windows Phone 8, IStorageFolder
, then getting the file, then file.OpenStreamForReadAsync()
), I'll just assume it's a text file for example purposes:
using(stream)
{
await client.UploadAsync("me/skydrive", "myfile.txt", stream, OverwriteOption.Overwrite);
}
Actually, I've used the overload that also accepts CancellationToken
and IProgress<LiveOperationProgress>
, mostly for progress notifications.
There, that should upload the file to the main directory on logged user's SkyDrive.
Upvotes: 4