System.Security.Permissions.SecurityPermission error?

May 9, 2011 at 12:06 AM

I am trying to extract the files from zip and it throws "System.Security.Permissions.SecurityPermission"

 string filePath = @"c:\FullInventory.zip";
        
        using (Stream s = File.OpenRead(filePath))
        {
            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(s))
            {
                foreach (Ionic.Zip.ZipEntry entry in zip)
                {
                    string test =  entry.FileName;
                    entry.Extract(@"c:\");
                }
            }
        }

May 10, 2011 at 12:40 PM

Sounds like you either don't have read permission to c:\FullInventory.zip or write permission to C:\.  This has nothing to do with DotNetZip and is an issue with the Windows user account and it's associated file system permissions.

I also find it easier to use this instead of a stream, unless you need the stream:

var filePath = @"c:\FullInventory.zip";

using (var zip = new ZipFile(filePath))
{
    // ...
}