Monday, October 14, 2013

Zip facility (Zip compression) with .NET Framework

This is very simple to create a zip file and extract this through .net framework,Many developers where using third party components like DotnetZip

Zip is one of the most accepted archive file formats. Zip format is supported in almost all operating systems with some built-in name.
  • In Windows operating system it’s implemented by the name “Compressed folders”.
  • In MAC OS it’s implemented by the name “Archive utility”.
Now in .NET we did not have built-in support for implementing Zip compression. Many developers where using third party components like “DotnetZip”. In .NET 4.5, the Zip feature is baked in the framework itself, inside the namespace System.IO.Compression.
The first step is you need to reference two namespaces:
  • System.IO.Compression.FileSystem
  • System.IO.Compression
If you want to Zip files from a folder you can use the CreateFromDirectory function as shown below.

If you wish to unzip, you can use the ExtractToDirectory function as shown in the below code.
ZipFile.ExtractToDirectory(@"D:\", @"D:\data\unzip");

1 comment:

  1. Excellent information on your blog, Thank you for taking the time to share with us. Amazing insight you have on this. It’s nice to find a website that details so much information.

    best .net training
    Dot net training