Edw*_*ard 6 silverlight windows-phone-7
当我尝试在WP7应用程序中打开文件时:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = new IsolatedStorageFileStream("Names.xml", System.IO.FileMode.Open, isf);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
IsolatedStorageFileStream上不允许操作.
我不确定为什么它没有打开,因为我在我的应用程序的其他地方使用了确切的代码,它工作正常.关于为什么会发生这种情况的任何线索?
编辑
我使用以下代码将文件添加到App.xaml.cs Application_Launching事件中的独立存储:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream feedXmlFile = new IsolatedStorageFileStream("Names.xml",System.IO.FileMode.Create, isf);
Run Code Online (Sandbox Code Playgroud)
使用构造函数的问题之一IsolatedStorageFileStream是生成的异常信息有限。替代OpenFile方法具有更丰富的例外情况。
作为一般经验法则,如果 API 允许您使用构造函数或方法执行相同的操作,请使用该方法。在这种情况下,请尝试使用此代码:-
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = isf.OpenFile("Names.xml", System.IO.FileMode.Open);
Run Code Online (Sandbox Code Playgroud)
如果失败,您至少可以缩小潜在原因的范围。
这可能看起来很明显,但在您的创建代码中,您实际上已经写入并关闭了您创建的文件?
| 归档时间: |
|
| 查看次数: |
4041 次 |
| 最近记录: |