This is a quick post about a useful third-party zip compression library if you’re working in .NET framework version 4 or earlier.
I had been working on a SQL Server Integration Services (SSIS) package. One of the steps in the package is to decompress a set of zip archives. Unfortunately, .NET script tasks in the SSIS package can only target .NET framework version 4 and earlier. This means that I couldn’t make use of the new zip compression classes introduced in .NET 4.5 (see
System.IO.Compression).
Fortunately though, there are a handful of open source .NET zip libraries available. The one I opted for is called
DotNetZip. DotNetZip has an intuitive API and is working well with a large number of files (I am decompressing approximately 15,000 archives). The library is available as a
NuGet package. The two snippets below show just how easy it is to compress and decompress files using zip.
-
-
- using (var zipFile = new ZipFile())
- {
-
-
- zipFile.AddFile(@“C:\Test\Data.txt”, string.Empty);
- zipFile.Save(@“C:\Test\Data.zip”);
- }
-
-
-
- using (var zipFile = new ZipFile(@“C:\Test\Data.zip”))
- {
- zipFile.ExtractAll(@“C:\Test\Output”);
- }