I am building a Windows Phone 7 application in Silverlight. I'm having difficulty with IsolatedStorage.
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
if (!storage.FileExists(STORIES_FILE))
{
storage.CreateFile(STORIES_FILE);
}
string contents;
using (IsolatedStorageFileStream stream = storage.OpenFile(STORIES_FILE, FileMode.Open))
{
using (StreamReader reader = new StreamReader(stream))
{
contents = reader.ReadToEnd();
}
}
The exception is:
"Operation not permitted on IsolatedStorageFileStream."
System.Exception {System.IO.IsolatedStorage.IsolatedStorageException}
What can i do wrong? MSDN says this exception is thrown when isolated storage is deleted or disconnected. Has this really happened? I am having this problem on an emulator.
Update . This only happens when you first run the application on the emulator. After the application crashes, I run it again on the emulator, and this problem does not occur.
Update 2 : using FileMode.OpenOrCreateinstead FileMode.Openseems to fix the problem.