Windows Phone中的IsolatedStorageFileStream不允许操作

Windows Phone中的IsolatedStorageFileStream不允许操作

问题描述:

第3条语句中出现以下异常,我正在尝试读取文件,但它不允许我打开读取流。Windows Phone中的IsolatedStorageFileStream不允许操作

这只是示例代码,但实际情况不同,web套接字试图将字节写入文件,而其他进程(音乐播放器)试图从同一文件中读取字节。我想要实现这种情况。

 IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication(); 

      var writeStream = storage.OpenFile("sample.txt", 
               System.IO.FileMode.OpenOrCreate, 
               System.IO.FileAccess.Write, 
               System.IO.FileShare.Read); 

      var readStream = storage.OpenFile("sample.txt", 
               System.IO.FileMode.Open, 
               System.IO.FileAccess.Read); 

System.IO.IsolatedStorage.IsolatedStorageException被抓住 的HResult = -2146233264 消息=操作不是IsolatedStorageFileStream允许的。 源= mscorlib程序 堆栈跟踪: 在System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(字符串路径, 的FileMode模式,FileAccess的访问,文件共享 份额,缓冲区大小的Int32,IsolatedStorageFile ISF) 在System.IO.IsolatedStorage.IsolatedStorageFile。的OpenFile(字符串路径, 的FileMode模式,FileAccess的访问) 在FileReadWriteSample.MainPage.Button_Click(对象发件人,RoutedEventArgs E)的InnerException:

+2

尝试提供'System.IO.FileShare.Read'参数你的第二个'OpenFile'电话,看看它是否解决了问题。 – 2013-04-26 13:38:22

该解决方案还为读取流提供文件访问权限。它解决了我的问题。

http://social.msdn.microsoft.com/Forums/en-us/wpdevelop/thread/f9e55760-e533-4124-a7ed-7f8f15e00e60

你已经打开了该文件流(通过第二条语句)。您需要首先处理该流,然后才能打开另一个流。

+0

http://social.msdn.microsoft.com/Forums/en-us/wpdevelop/thread/f9e55760-e533-4124-a7ed-7f8f15e00e60 – 2013-04-27 04:51:40