0

I have 2 apps, one which uploads a simple text file to Skydrive, and another which retrieves it. I got the upload bit working fine, but how on earth do I get the file ID to download the same file from SkyDrive? :(

I tried using some code from http://wp.qmatteoq.com/backup-and-restore-on-skydrive-in-windows-phone/ , but for WP8 they have removed the event handler on GetAsycn()

Any help is much appreciated as always

4

1 回答 1

1

What a tricky bit of code.. for anyone interested, here's how you do it:

// 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();
        }
    }
}
于 2013-05-31T16:37:09.427 回答