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

前端之家收集整理的这篇文章主要介绍了silverlight – 在文件打开时抛出IsolatedStorageFileStream异常?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_6@ 当我尝试在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);

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

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

猜你在找的Silverlight相关文章