2013-06-24 43 views
0

當我嘗試從SkyDrive下載文件時,應用程序崩潰。 如果我再次打開應用程序,它的工作原理。當我嘗試從SkyDrive下載文件時出錯

什麼可能是錯的?

這裏是xaml.cs:

namespace SDKMiniBrowserCS 
{ 
    public partial class Address : PhoneApplicationPage 
    { 
     private LiveConnectClient client = null; 
     private IsolatedStorageFileStream stream; 
     IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 
     IsolatedStorageSettings inviato = IsolatedStorageSettings.ApplicationSettings; 
    public Address() 
    { 
     InitializeComponent(); 
     Loaded += Customers_Loaded; 



    } 




    void Customers_Loaded(object sender, RoutedEventArgs e) 
    { 
     using (AddressBookDataContext dc = new AddressBookDataContext()) 
     { 
      var itemSource = (from c in dc.Contacts select c).AsEnumerable(); 
      ContactListBox.ItemsSource = from c in itemSource orderby c.Name ascending select c; 

     } 
    } 



    private void Edit_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     NavigationService.Navigate(
      new Uri(string.Format("/AddressDetail.xaml?Id={0}", (ContactListBox.SelectedItem as AddressUser).Id), UriKind.Relative)); 
    } 

    private void Go_Fav(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     inviato["inviato"] = (ContactListBox.SelectedItem as AddressUser).Url; 
     inviato["pannello"] = "1"; 
     inviato.Save(); 
     NavigationService.GoBack(); 
     } 



    private void AddCustomerButton_Click(object sender, EventArgs e) 
    { 
     NavigationService.Navigate(new Uri("/AddressDetail.xaml", UriKind.Relative)); 
    } 


    private void SignInButton_OnSessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e) 
    { 
     if (e.Status == LiveConnectSessionStatus.Connected) 
     { 
      client = new LiveConnectClient(e.Session); 
      restore.IsEnabled = true; 
      btnBackup.IsEnabled = true; 
     } 
    } 

    private void OnBackupClicked(object sender, RoutedEventArgs e) 
    { 
     client.UploadCompleted += client_UploadCompleted; 
     using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      stream = storage.OpenFile("3VSwipeBrowser.sdf", FileMode.Open); 
      client.UploadAsync("me/skydrive/my_documents", "3VSwipeBrowser.sdf", stream, OverwriteOption.Overwrite, null); 
     } 
    } 

    void client_UploadCompleted(object sender, LiveOperationCompletedEventArgs e) 
    { 
     if (e.Error == null) 
     { 
      MessageBox.Show("Upload successfull!"); 
      stream.Close(); 
     } 
    } 

    private void OnRestoreClicked(object sender, RoutedEventArgs e) 
    { 
     string id = string.Empty; 
     client.GetCompleted += (obj, args) => 
     { 
      List<object> items = args.Result["data"] as List<object>; 
      foreach (object item in items) 
      { 
       Dictionary<string, object> file = item as Dictionary<string, object>; 
       if (file["name"].ToString() == "3VSwipeBrowser.sdf") 
       { 
        id = file["id"].ToString(); 
       } 
      } 

      client.DownloadCompleted += (o, a) => 
      { 
       Stream stream = a.Result; 
       using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
       { 
        using (
         IsolatedStorageFileStream fileToSave = storage.OpenFile("3VSwipeBrowser.sdf", FileMode.Create, 
                       FileAccess.ReadWrite)) 
        { 
         stream.CopyTo(fileToSave); 
         stream.Flush(); 
         stream.Close(); 
        } 
       } 
      }; 

      client.DownloadAsync(string.Format("{0}/content", id)); 
     }; 

     client.GetAsync("me/skydrive/my_documents/files"); 
     MessageBox.Show("Download successfull!"); 
     NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); 
    } 

}}

錯誤是在該行:

IsolatedStorageFileStream fileToSave = storage.OpenFile( 「3VSwipeBrowser.sdf」,FileMode.Create ,FileAccess.ReadWrite))

謝謝

回答

0

FileAccess.ReadWrite))必須是FileAccess.ReadWrite)我認爲

+0

對不起,我沒有很好地分析代碼。你使用真正的VB還是SharpDevelop? – 2013-06-24 09:09:47

+0

我正在使用C Sharp – Alessandro

+0

對不起,我不知道...嘗試使用另一個庫來做到這一點...有時系統庫也不知道...嘗試更新您的環境... – 2013-06-24 09:42:09