IsolatedStorageException on first cache access
I am having an issue where I am getting an IsolatedStorageException ('Operation not permitted on IsolatedFileStorageStream') every first time I run an app. Consequent times of running the app, it works just fine. I have tried every method I could find of open files for writing, including
using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
using (IsolatedStorageFileStream file = new IsolatedStorageFileStream(fileName, FileMode.Create, FileAccess.Write, iso))
{
}
using(var iso = IsolatedStorageFile.GetUserStoreForApplication())
using(IsolatedStorageFileStream file = iso.OpenFile(fileName, FileMode.OpenOrCreate))
{
}
and other various overloads of those metho开发者_JS百科ds. Nothing I do has worked, and I have followed the steps on every other post in Stack Overflow and every blog post I could find. When I look at the output, every time it throws the following exceptions:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Windows.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Windows.dll
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.dll
Does anyone have any other ideas as to why it's exploding? I'm using WP7 7.1 RTM tools.
This is were i learned how to write to isolated storage on the WP7,
Using Isolated Storage on Windows Phone 7
Hope this helps! :)
Try this one,
if (!myStore.DirectoryExists(directory))
{
myStore.CreateDirectory(directory);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var isoFileStream = myIsolatedStorage.CreateFile(directory+"//yourfilename.jpg"))
{
//her what do you want....
}
}
}
It turned out that if you have a file name with funny characters in it, you will get an exception, but then for some reason it accepts the file name.
精彩评论