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

本文关键字:skydrive 下载和 保存文件 WP7 | 更新日期: 2023-09-27 18:10:04

我必须将文件从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中保存文件?

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

我找到解决办法了:

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();
        }
    }
}