当我尝试在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);
如果失败,您将至少缩小潜在原因.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。