gpt4 book ai didi

c# - IsolatedStorageFile 的 MoveFile() 方法抛出 IsolatedStorageException

转载 作者:行者123 更新时间:2023-11-30 16:23:40 31 4
gpt4 key购买 nike

描述:

下面的代码是我能写的导致失败的最简单的代码。我也尝试过:将 CreateFile 和 MoveFile 放在不同的 using 语句中,将它们放在不同的 xaml 页面中,将文件移动到具有新文件名的子目录中,将其移动到具有相同文件名的子目录中。他们都抛出相同的异常。 CopyFile 在所有情况下都会抛出相同的异常。

问题是——我没有考虑到什么非常简单的事情?

  1. 针对 Windows Phone 7.1 打开一个新的 Silverlight for Windows Phone 7 项目。
  2. 打开 App.xaml.cs。
  3. 将以下代码行粘贴到 Application_Launching 中:

    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()){    isf.CreateFile("hello.txt");    isf.MoveFile("hello.txt", "hi.txt");}
  4. 点击开始调试,针对模拟器或设备。

预期:创建一个名为“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()

最佳答案

您应该在创建文件后调用Close

IsolatedStorageFileStream helloFile = store.CreateFile("hello.txt");
helloFile.Close();
isf.MoveFile("hello.txt", "hi.txt");

关于c# - IsolatedStorageFile 的 MoveFile() 方法抛出 IsolatedStorageException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385965/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com