System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream in Windows Phone 8 App

I was recently try out some samples using Windows Phone 8 SDK and one such sample was using Isolated Storage . After trying it out for some time , i ended up getting the below error when creating a new file in the isolated storage.

“An exception of type ‘System.IO.IsolatedStorage.IsolatedStorageException’ occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Operation not permitted on IsolatedStorageFileStream.”

image

For example , when try to execute the below code , you might get the above error.

private void Button_Click(object sender, RoutedEventArgs e)
{
    // Create a file in Isolated Storage
    IsolatedStorageFile storage= IsolatedStorageFile.GetUserStoreForApplication();
    storage.CreateFile("developerpublish\test.txt");
}

One of the reasons for the above error was the invalid directory . The directory “developerpublish” does not exist where we are trying to create the text file under this directory . Before creating the file under the directory(that does not exist) , first we need to create the Directory.

Below is the modified code to handle this.

private void Button_Click(object sender, RoutedEventArgs e)
{
   // Create a file in Isolated Storage
   IsolatedStorageFile storage= IsolatedStorageFile.GetUserStoreForApplication();
   storage.CreateDirectory("developerpublish");
   if (storage.FileExists("developerpublish\test.txt"))
     storage.DeleteFile("developerpublish\test.txt");
   storage.CreateFile("developerpublish\test.txt");
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...