Using the new ZipArchive class

We have two new classes, ZipArchive and ZipArchiveEntry, which add the capability to create .zip archives to the .NET framework. This was possible previously, but with several limitations.

How to do it...

Next we will see how to use the ZipArchive class to create a Zip file and to extract it to a concrete location.

  1. Create a new Visual Studio project of type Console Application named caZipArchive.
  2. Add the System.IO.Compression and System.IO.Compression.Filesystem assemblies as references to the project.
  3. Open the Program.cs file and add the following using clauses:
    using System.IO;
    using System.IO.Compression;
  4. Next, add the following method:
    static void CreateZipFile() { String ZipPath= @"C:\PACKT\02-CLR\caZipArchive\test\"; ...

Get Microsoft .NET Framework 4.5 Quickstart Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.