【问题标题】:Operation not permitted on IsolatedStorageFileStream for CreateFile in isolated storage不允许对独立存储中的 CreateFile 的独立存储文件流进行操作
【发布时间】:2026-01-14 16:00:02
【问题描述】:

我正在尝试使用以下代码在独立存储中创建一个文件,

IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
storageFile.CreateFile("Html\\index.html");

但我在做同样的事情时遇到了异常......这说明了。

System.IO.IsolatedStorage.IsolatedStorageException:IsolatedStorageFileStream 上不允许操作

除此操作外不执行任何操作。

【问题讨论】:

  • 您是否先创建了Html 文件夹?另外,您确定index.html 文件不存在吗?

标签: c# windows-phone windows-phone-8 isolatedstorage isolatedstoragefile


【解决方案1】:

我有同样的问题,它是目录路径。

此代码用于写入文件。

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
    var folder = ApplicationData.Current.LocalFolder;
    string folderfilename = folder.Path + "\\" + fileName;
    try
    {
        StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(folderfilename, FileMode.OpenOrCreate, myIsolatedStorage));
        writeFile.WriteAsync(content);
        writeFile.Close();
    }
    catch (Exception ex)
    {
    }

【讨论】:

    【解决方案2】:

    您可能需要先创建Html 目录。如果目录已经存在,IsolatedStorageFile.CreateDirectory() 会成功,你可以这样做

    IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
    storageFile.CreateDirectory("Html");
    storageFile.CreateFile("Html\\index.html");

    【讨论】:

    • 在创建文件之前我正在做一个“isf.FileExists()”检查,但我仍然面临这个问题。在创建文件之前,我还创建了 Html 文件夹。仍然得到相同的异常 - mscorlib.ni.dll 中发生了“System.IO.IsolatedStorage.IsolatedStorageException”类型的异常,但未在用户代码中处理----
    • IsolatedStorageException的InnerException里面有什么东西吗?