locked
Operation not permitted on IsolatedStorageFileStream.

    Question

  • I have been trying to store data on the client machine using Isolated storage. I am able to do so using the isolated storage. However I am getting a random exception "Operation not permitted on IsolatedStorageFileStream."

     using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (isoStore.FileExists("DiagnosesInfo.xml"))
                    {
                        using (var isoStream = new IsolatedStorageFileStream("DiagnosesInfo.xml", FileMode.Open, isoStore))
                        {
                            //Get the data from isolated storage
                            XDocument xDoc = XDocument.Load(isoStream);
                            int count = Convert.ToInt32(xDoc.Root.Element("Count").Value, CultureInfo.InvariantCulture);
                            for (int i = 0; i < count; i++)
                            {
                                icd10EntityList.Add(new ICD10Entity()
                                {
                                    DiagnosisCodeField = xDoc.Root.Element("DiagnosisCodeField" + i).Value.ToString(),
                                    DiagnosisNameField = xDoc.Root.Element("DiagnosisNameField" + i).Value.ToString()                            
                                });
                            }
                        }
                    }
                    else
                    {
                         //store data in isolated storage.
                    }
              }


    I am getting the exceptin when

    using (var isoStream = new IsolatedStorageFileStream("DiagnosesInfo.xml", FileMode.Open, isoStore)) 

    statement is executed. I checked if the DiagnosesInfo.xml is present  in the respective folder.It is present in the store.This problem occours when i restart my system.If i clear the isolated storage and create it again then the error goes.

     

     

     

    Wednesday, May 05, 2010 8:22 AM

Answers

  • A good rule of thumb is to use a Try/Catch block to surround any code that can throw exceptions beyond your control.  Disk drive access and File I/O would meet this description.  You never know when you might get disk and network errors.
    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by Savira Monday, May 10, 2010 6:10 AM
    Thursday, May 06, 2010 12:50 PM
    Moderator

All replies

  • Try FileMode.OpenOrCreate.

    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, May 05, 2010 4:36 PM
    Moderator
  • I tried FileMode.OpenOrCreate but  I am still getting the error. It is very random and occours only sometimes. Is there a way I can put any check...
     
    Thursday, May 06, 2010 6:57 AM
  • A good rule of thumb is to use a Try/Catch block to surround any code that can throw exceptions beyond your control.  Disk drive access and File I/O would meet this description.  You never know when you might get disk and network errors.
    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by Savira Monday, May 10, 2010 6:10 AM
    Thursday, May 06, 2010 12:50 PM
    Moderator