从skydrive获取文件ID

时间:2013-05-31 14:16:29

标签: .net windows-phone-8 onedrive

我有2个应用程序,一个将简单的文本文件上传到Skydrive,另一个用于检索它。我上传位工作正常,但我怎么得到文件ID从SkyDrive下载相同的文件? :(

我尝试使用http://wp.qmatteoq.com/backup-and-restore-on-skydrive-in-windows-phone/中的一些代码,但对于WP8,他们已经删除了GetAsycn()上的事件处理程序

任何帮助都一如既往地受到赞赏

1 个答案:

答案 0 :(得分:1)

对于任何感兴趣的人来说,这是多么棘手的代码......这就是你如何做到的:

// This button reads the file from skydrive and puts it into isolated storage
private async void Button_Click(object sender, RoutedEventArgs e)
{
    string id = string.Empty;
    LiveOperationResult result = await this.client.GetAsync("me/skydrive/files");

    List<object> items = result.Result["data"] as List<object>;

    foreach (object item in items)
    {
        IDictionary<string, object> file = item as IDictionary<string, object>;
        if (file["name"].ToString() == "somefile.txt")
        {
            id = file["id"].ToString();
        }
    }

    MessageBox.Show(id.ToString());

    LiveDownloadOperationResult result2 = await client.DownloadAsync(string.Format("{0}/content", id));
    Stream stream = result2.Stream;
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream fileToSave = storage.OpenFile("foo.txt", FileMode.Create, FileAccess.ReadWrite))
        {
            stream.CopyTo(fileToSave);
            stream.Flush();
            stream.Close();
        }
    }
}