6

I am trying to create a file in the Isolated storage using following code,

IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
storageFile.CreateFile("Html\\index.html");

but I am getting exception while doing the same.. which says.

System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream

There are no operation performed apart from this operation.

1
  • Have you created the Html folder first? Also, are you sure the index.html file doesn't already exist? Dec 12, 2012 at 14:08

2 Answers 2

3

You probably need to create the Html directory first. As IsolatedStorageFile.CreateDirectory() will succeed if the directory already exists, you can just do

IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
storageFile.CreateDirectory("Html");
storageFile.CreateFile("Html\\index.html");
2
  • I am doing a "isf.FileExists()" check before creating the file, but I am still facing the problem. I also created the Html folder before creating the file. STill getting the same exception -- An exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.ni.dll but was not handled in user code ---- Dec 13, 2012 at 6:58
  • Is there anything in the InnerException of the IsolatedStorageException?
    – gregstoll
    Dec 14, 2012 at 1:29
1

I had the same problem and it was the directory path.

This code worked to write to a file.

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
    var folder = ApplicationData.Current.LocalFolder;
    string folderfilename = folder.Path + "\\" + fileName;
    try
    {
        StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(folderfilename, FileMode.OpenOrCreate, myIsolatedStorage));
        writeFile.WriteAsync(content);
        writeFile.Close();
    }
    catch (Exception ex)
    {
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.