0

I wrote a program that unzip a file (.zip) using SharpZipLib...

The following code:

public void UnZip(string zipFilePath, string extractionPath)
{
     FastZip fz = new FastZip();
     fz.ExtractZip(zipFilePath, extractionPath, null);
}

I get the following Exception:
Additional information: The access to the path "C:\Program files (x86)\... Thumbs.db" was refused.
The program starts with Admin rights and the file "Thumbs.db" does not exist in the .zip archive.

Who knows further?
Greets and thanks!

digEmAll
  • 56,430
  • 9
  • 115
  • 140
Nick_SMI
  • 43
  • 1
  • 6
  • `Thumbs.db` is a windows-internal file to story preview pictures / miniature pictures for a folder containing images. Can look in the zip and verify the existance of that file? Can you create a zip file without such a file, and try to extract it? Your problem may also just be that you're trying to extract it to `C:\Program files (x86)\..` to which you don't have write access to. Try unzipping it in the current directory or to the desktop for debugging. – Maximilian Gerhardt Mar 26 '16 at 12:20
  • Thanks for your comment! I'll try it in a few minutes... But I should have the access to the path because the programm starts with admin-rights (app.manifest-data) – Nick_SMI Mar 26 '16 at 12:37

1 Answers1

0

I would ignore the "Thumbs.db" file as its an OS file.

Maybe something like this:

using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;

public void ExtractZipFile(string archiveFilenameIn, string password, string outFolder) {
    ZipFile zf = null;
    try {
        FileStream fs = File.OpenRead(archiveFilenameIn);
        zf = new ZipFile(fs);
        if (!String.IsNullOrEmpty(password)) {
            zf.Password = password;     // AES encrypted entries are handled automatically
        }
        foreach (ZipEntry zipEntry in zf) {
            if (!zipEntry.IsFile) {
                continue;           // Ignore directories
            }
            String entryFileName = zipEntry.Name;
            // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
            // Optionally match entrynames against a selection list here to skip as desired.
            // The unpacked length is available in the zipEntry.Size property.

            byte[] buffer = new byte[4096];     // 4K is optimum
            Stream zipStream = zf.GetInputStream(zipEntry);

            // Manipulate the output filename here as desired.
            String fullZipToPath = Path.Combine(outFolder, entryFileName);
            string directoryName = Path.GetDirectoryName(fullZipToPath);
            if (directoryName.Length > 0)
                Directory.CreateDirectory(directoryName);

            // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
            // of the file, but does not waste memory.
            // The "using" will close the stream even if an exception occurs.
            using (FileStream streamWriter = File.Create(fullZipToPath)) {
                StreamUtils.Copy(zipStream, streamWriter, buffer);
            }
        }
    } finally {
        if (zf != null) {
            zf.IsStreamOwner = true; // Makes close also shut the underlying stream
            zf.Close(); // Ensure we release resources
        }
    }
}
William Humphreys
  • 1,206
  • 1
  • 14
  • 38
  • That doesn't work, I get an exception: "ICSharpCode. SharpZipLib. Zip. ZipFile" contains no definition for "Read" and "SelectEntries" – Nick_SMI Mar 26 '16 at 12:42
  • Ive edited the above code. This is from their own documentation. I have no way to test this now as Im typing this from my phone. I would be looking for that file roughly after the line above that reads "String entryFileName = zipEntry.Name;" – William Humphreys Mar 26 '16 at 12:55