when I attempt to open a file in a WP7 app:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = new IsolatedStorageFileStream("Names.xml", System.IO.FileMode.Open, isf);
I recieve the following error:
Operation not permitted on IsolatedStorageFileStream.
I'm not sure why it isn't opening because I used the exact code somewhere else in my app and it works fine. Any leads as to why this is happening?
EDIT
I used the following code to add the file to isolated storage in the App.xaml.cs Application_Launching Event:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream feedXmlFile = new IsolatedStorageFileStream("Names.xml",System.IO.FileMode.Create, isf);
One of the problems with using the IsolatedStorageFileStream
constructor is that the exception generated has limited info. The alternative OpenFile
method has a richer set of exceptions.
As a general rule of thumb if an API allows you to do the same thing with a constructor or with a method go with the method. In this case try this code instead:-
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = isf.OpenFile("Names.xml", System.IO.FileMode.Open);
If this fails you will have at least narrowed down the potential cause.
This may seem obvious but in your creation code you have actually written to and closed the file you created?
IsolatedStorage Exception is a known issue whil fires Application_Launching. more details
When you run into an exception during file access, check for two things:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With