3

我想用 SkyDrive 来备份一些信息。

但似乎他们已经Microsoft.Live.Controls;从新的 SDK 中删除了这个命名空间,并且这里的所有代码示例和答案都已过时。

参考文献也已过时;没有了LiveConnectClient

在这些更改之后,我如何简单地将文件备份到 SkyDrive?

(感谢任何代码示例或参考。)

4

1 回答 1

4

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.

于 2013-09-03T10:51:43.493 回答