gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:35:00 24 4
gpt4 key购买 nike

当我尝试在 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 - 打开文件时抛出IsolatedStorageFileStream异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4512165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com