隔离存储中的CreateFile的IsolatedStorageFileStream上不允许操作

use*_*772 6 c# isolatedstorage isolatedstoragefile windows-phone windows-phone-8

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

IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
storageFile.CreateFile("Html\\index.html");
Run Code Online (Sandbox Code Playgroud)

但是我在做同样的事情时会遇到异常.

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

除此操作外,不执行任何操作.

gre*_*oll 3

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

IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
storageFile.CreateDirectory("Html");
storageFile.CreateFile("Html\\index.html");
Run Code Online (Sandbox Code Playgroud)