Wednesday, 18 March 2009

Zip/Unzip files in C#

DotNetZip is an OpenSource Zip library for C#

public void ZipDir(string directoryPath, string zipFilePath)
{
  using(ZipFile zip = new ZipFile())
  {
    zip.AddDirectory(directoryPath);
    zip.Save(zipFilePath);
  }            
}
public void UnzipDir(string zipFilePath, string directoryPath)
{
  using(ZipFile zip = ZipFile.Read(zipFilePath))
  {                                
    zip.ExtractAll(directoryPath,true);                
  }            
}
public void UnzipFile(string zipFilePath, string directoryPath, string fileName)
{
  using (ZipFile zip = ZipFile.Read(zipFilePath))
  {
    zip.Extract(fileName, directoryPath, true);
  }
}

No comments:

Post a Comment