2013-05-29 18 views
0

私人無效OnRestoreClicked(對象發件人,RoutedEventArgs E) {數據庫文件恢復從SkyDrive的錯誤

 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() == "Expensemanager.bak") 
       { 
        id = file["id"].ToString(); 
       } 
      } 

      client.DownloadCompleted += (o, a) => 
      { 
       Stream stream = a.Result; 

       using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
       {  
         var fileToSave = new IsolatedStorageFileStream("expanseManager.sdf", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, storage); 

         stream.CopyTo(fileToSave); 
         stream.Flush(); 
         stream.Close(); 

       } 
      }; 

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

     client.GetAsync("me/skydrive/files"); 
    } 

錯誤在此線之下運行...不允許在獨立存儲上。

var fileToSave = new IsolatedStorageFileStream(「expanseManager.sdf」,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None,storage);

回答

0

您需要確保您的數據庫已關閉,然後才能覆蓋sdf文件。如果您保留全局DataContext引用,那麼您需要處理它。除此之外,只要確保將數據庫交互包裝在using區塊中。

+0

謝謝你阿拉:) –