Operation not permitted on IsolatedStorageFileStream for CreateFile in isolated storage
Asked Answered
H

2

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.

Hypersonic answered 12/12, 2012 at 13:55 Comment(1)
Have you created the Html folder first? Also, are you sure the index.html file doesn't already exist?Selenaselenate
C
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");
Cadelle answered 12/12, 2012 at 15:23 Comment(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 ----Hypersonic
Is there anything in the InnerException of the IsolatedStorageException?Cadelle
S
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)
    {
    }
Soilasoilage answered 4/6, 2013 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.