0

I have a directory and I'm using a compression tool to compress directory into a zip file but after I finished the zipping operation I get an error saying: isolated storage operation not permitted.

This error only occurs occasionally.

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

C1ZipFile zip = new C1.C1Zip.C1ZipFile();

if (isf.DirectoryExists("SFA_DB") == true)
{
   var fs = isf.CreateFile("\\SFA_DB.zip");
   zip.Create(fs);
   foreach (string fileName in isf.GetFileNames("SFA_DB\\*.*"))
        zip.Entries.Add(isf.OpenFile("SFA_DB\\" + fileName, FileMode.Open), fileName);
   fs.Close();
   fs.Dispose();
   zip.Close();
 }

//Last Two Lines I have writtent recently
isf.Dispose(); 
isf = null;

Zipping tool is provided by Component One C1.Phone.Zip.8

Is there anything I'm doing wrong or misunderstanding ?

gayan1991
  • 753
  • 2
  • 11
  • 35

1 Answers1

0

Looks like you are not disposing the object, to quote from this answer:

Setting the object to null may result in leaving out un-managed resources un-disposed. The whole object of having IDisposable is to make sure that un-managed resources are disposed after their usage.

So what I would do: remove the isf = null; line and wrap it all in a using statement.

Community
  • 1
  • 1
Kajzer
  • 2,138
  • 3
  • 32
  • 46