0

Im developing a c# application which has to zip all the content within a directory.. Is this possible?

thanks

  • right, there should be many solutions like here: https://github.com/search?langOverride=&language=C%23&q=zip&repo=&start_value=1&type=Repositories –  Jun 22 '12 at 13:59
  • 1
    @nima Don't tell users to ask elsewhere. Questions can always be migrated. When you tell them to ask somewhere else this will lead to cross posting. In the future just let community members migrate the question. Thanks! – slhck Jun 22 '12 at 14:23

3 Answers3

2

Yes you can.DotNetZip supports adding a Directory to a zip file with the ZipFile.AddDirectory() methods.

To zip up an entire directory, recursively:

using (ZipFile zip = new ZipFile())
{
  zip.UseUnicode= true;  // utf-8
  zip.AddDirectory(@"MyFile");
  zip.Save(ZipFileToCreate);
}
ahmed
  • 879
  • 3
  • 11
  • 24
  • This answer worked for me, however it is important to note that in later versions of .DotNetZip library, the zip.UseUnicode=true line has been deprecated and so that line is no longer needed. – Douglas Timms Jul 08 '15 at 16:04
0

See the documentation for class ZipFile at http://msdn.microsoft.com/en-us/library/system.io.compression.zipfile(v=vs.110).aspx.

UPDATE: This class is only available in .NET 4.5, which is not installed as part of Windows 7. You would have to download it from Microsoft.

0

You can use also SevenZipSharp like so:

SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressDirectory(...);
d.popov
  • 4,175
  • 1
  • 36
  • 47