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.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94
user1893772
  • 83
  • 1
  • 5

2 Answers2

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");
gregstoll
  • 1,318
  • 9
  • 14
  • 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 ---- – user1893772 Dec 13 '12 at 06:58
  • Is there anything in the InnerException of the IsolatedStorageException? – gregstoll Dec 14 '12 at 01: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)
    {
    }
Eric
  • 389
  • 5
  • 8