4
votes

"Operation not permitted on IsolatedStorageFileStream." is pointing towards the line of codes:

var fileStream = storage.OpenFile(item.FileName, FileMode.Open, FileAccess.Read) 

in the codes below:

private void OnReadSelected()
            {
                IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
                List<FileItem> readItems = new List<FileItem>();
                foreach (var item in Files)
                {
                    if (item.IsChecked)
                        if (storage.FileExists(item.FileName))
                        {
                            storage.DeleteFile(item.FileName);
                            readItems.Add(item);
                        }
                }
                 foreach (var item in readItems)
                     using (var fileStream = storage.OpenFile(item.FileName, FileMode.Open, FileAccess.Read))
                     {
                         using (var reader = new StreamReader(fileStream))
                         {
                             item.FileName = reader.ReadLine();
                             item.FileText1 = reader.ReadLine();

                             item.RdbText1 = reader.ReadLine();

                         }
                     }
            }

Am I to use another derivative besides StreamReader?

1

1 Answers

2
votes


foreach (var item in Files)
{
    if (item.IsChecked)
        if (storage.FileExists(item.FileName))
        {
           storage.DeleteFile(item.FileName);
           readItems.Add(item);
        }
}

You have used this code to delete some files from the store depending upon the condition if(item.IsChecked). And you are adding those items to the readItems collection. But in this code


foreach (var item in readItems)
                     using (var fileStream = storage.OpenFile(item.FileName, FileMode.Open, FileAccess.Read))
                     {
                         using (var reader = new StreamReader(fileStream))
                         {
                             item.FileName = reader.ReadLine();
                             item.FileText1 = reader.ReadLine();
                             item.RdbText1 = reader.ReadLine();
                         }
                     }

you are trying to open the files which you have just deleted from the store.
So, you are getting the exception Operation not permitted on IsolatedStorageFileStream as the files doesn't exist in the store.