2013-05-31 45 views

回答

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