描述:IsolatedStorageFile的MoveFile()方法拋出IsolatedStorageException
下面的代碼是我可以編寫的導致失敗的最簡單的代碼。我也嘗試過:將CreateFile和MoveFile放入不同的使用語句中,將它們放在不同的xaml頁面中,將文件移動到具有新文件名的子目錄中,並將其移動到具有相同文件名的子目錄中。他們都拋出同樣的例外。 CopyFile在所有情況下都引發相同的異常。
問題是 - 什麼令人難以置信的簡單的事情我不佔?
- 爲針對Windows Phone 7.1的Windows Phone 7項目打開一個新的Silverlight。
- 打開App.xaml.cs.
的下面幾行代碼粘貼到Application_Launching:
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { isf.CreateFile("hello.txt"); isf.MoveFile("hello.txt", "hi.txt"); }
點擊開始調試,靶向模擬器或設備。
預計:創建名爲「hello.txt」的文件,然後(有效地)將「hello.txt」重命名爲「hi.txt」。
實際:在下面引發異常。
System.IO.IsolatedStorage.IsolatedStorageException was unhandled Message=An error occurred while accessing IsolatedStorage. StackTrace: at System.IO.IsolatedStorage.IsolatedStorageFile.MoveFile(String sourceFileName, String destinationFileName) at PhoneApp4.App.Application_Launching(Object sender, LaunchingEventArgs e) at Microsoft.Phone.Shell.PhoneApplicationService.FireLaunching() at Microsoft.Phone.Execution.NativeEmInterop.FireOnLaunching()