0
votes

I have developed a system to send a mail with attachments (zip files). One of the attachment is a folder, which I convert it to Zip file before send. Mails are sent perfectly. However, after I sent the mail with Zips whenever I try to access the Isolated Storage again or do any modification to files in isolated storage I get an Operation not permitted on IsolatedStorageFileStream..

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();
}

isf.Dispose();
isf = null;

What code am I missing or is there any operation that I have to do differently?

Thanks in advance

1
where in this code is the error occurring?Matt Lacey
actually I have found the error and corrected it, Thanks thoughgayan1991

1 Answers

0
votes
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

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

    if (isf.DirectoryExists("SFA_DB") == true)
        using (IsolatedStorageFileStream fileStream = isf.CreateFile("\\SFA_DB.zip"))
        {
              zip.Create(fileStream);

              foreach (string fileName in isf.GetFileNames("SFA_DB\\*.*"))
                       zip.Entries.Add(fileStream, fileName);
              fileStream.Dispose();
              fileStream.Close();
              zip.Close();
        }

    isf.Dispose();
    isf = null;