Friday, September 11, 2015

NET Framework 4.5 Zip facility (Zip compression)

It 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 namespaceSystem.IO.Compression.
The first step is you need to reference two namespaces:
  • System.IO.Compression.FileSystem
  • System.IO.Compression
The next step is to import the below two namespaces:

Code Block :
 
using System.IO.Compression; 
Namespace zip
{
Class zip
{
ZipFile.CreateFromDirectory(@"D:\data",@"D:\data.zip");
ZipFile.ExtractToDirectory(@"D:\data.zip", @"D:\data\unzip");
}
}

No comments:

Post a Comment