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

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...