Search code examples
c#zipdotnetzip

DotNetZip: How to extract files, but ignoring the path in the zipfile?


Trying to extract files to a given folder ignoring the path in the zipfile but there doesn't seem to be a way.

This seems a fairly basic requirement given all the other good stuff implemented in there.

What am i missing ?

code is -

using (Ionic.Zip.ZipFile zf = Ionic.Zip.ZipFile.Read(zipPath))
{
    zf.ExtractAll(appPath);
}

Solution

  • You'll need to remove the directory part of the filename just prior to unzipping...

    using (var zf = Ionic.Zip.ZipFile.Read(zipPath))
    {
        zf.ToList().ForEach(entry =>
        {
            entry.FileName = System.IO.Path.GetFileName(entry.FileName);
            entry.Extract(appPath);
        });
    }