Friday, October 7, 2011

Using DotNetZip to Compress all the Files in a Folder in C#

The inbuilt Compression class GzipStream class(System.IO.Compression) for C# does not provide the ability to compress all the files within a folder.You can do this by just few lines of code and just forgetting the techinical aspects behind it by using DotNetZip(Ioniczip).DotNetZip is a free class library that can be used for creating and editing zip files.

The project is Hosted at CodePlex check out http://dotnetzip.codeplex.com
To use DotNetZip Library in your C# Project follow these steps
  • Download the latest release from http://dotnetzip.codeplex.com/releases/
  • Add a Reference to DotNetZip from your project by going to Project> Add Reference .Browse for Ionic.Zip.dll in the release that you have downloaded.
  • Then add the reference in your project by adding the statement 'using Ionic.Zip'
  • Then use the code given below to create a zip file from a folder
 using (ZipFile zip = new ZipFile())  
 {  
   zip.AddDirectory(@"thefoldertoadd");  
   zip.Save("pathToSaveZipFile");  
 }  

No comments:

Post a Comment

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...