silverlight – 在文件打开时抛出IsolatedStorageFileStream异常?

当我尝试在WP7应用程序中打开文件时:

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = new IsolatedStorageFileStream("Names.xml",System.IO.FileMode.Open,isf);

我收到以下错误:

Operation not permitted on IsolatedStorageFileStream.

我不确定为什么它没有打开,因为我在我的应用程序的其他地方使用了确切的代码,它工作正常.
关于为什么会发生这种情况的任何线索?

编辑

我使用以下代码将文件添加到App.xaml.cs Application_Launching事件中的独立存储:

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream feedXmlFile = new IsolatedStorageFileStream("Names.xml",System.IO.FileMode.Create,isf);

解决方法

使用IsolatedStorageFileStream构造函数的一个问题是生成的异常信息有限.替代的OpenFile方法有一组更丰富的例外.

作为一般的经验法则,如果API允许您使用构造函数或方法执行相同的操作,请使用该方法.在这种情况下,请尝试使用此代码: –

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = isf.OpenFile("Names.xml",System.IO.FileMode.Open);

如果失败,您将至少缩小潜在原因.

这看起来很明显但是在您创建的代码中,您实际上已经写入并关闭了您创建的文件?

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...