WP7 - 如何从skydrive下载和保存文件

时间:2013-04-20 13:07:01

标签: c# windows-phone-7 onedrive live-sdk

我必须将skdrive文件夹中的文件保存到我的隔离存储中(如果存在隔离存储中的文件,则覆盖它们)。

这是我的代码:

    private void RestoreData(LiveConnectClient liveClient, string storedFolderId)
    {
        liveClient.DownloadCompleted += liveClient_DownloadCompleted;
        liveClient.DownloadAsync(storedFolderId + "/content");
    }

    private void liveClient_DownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
    {
        Stream stream = e.Result;

        // HOW TO SAVE FILES ON IN THIS METHOD?
    }

如何在方法liveClient_DownloadCompleted中保存文件?

1 个答案:

答案 0 :(得分:1)

我找到解决方案:

private void liveClient_DownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
{
    Stream stream = e.Result;

    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream fileToSave = storage.OpenFile("tasks.xml", FileMode.Create, FileAccess.ReadWrite))
        {
            stream.CopyTo(fileToSave);
            stream.Flush();
            stream.Close();
        }
    }
}