Matrosov Alexander Matrosov Alexander - 2 months ago 8
C# Question

How to zip all files in folder

I have a folder

and in this folder I have 10 files that I need to zip into a new archive

Currently I'm using ICSharpCode.SharpZipLib but this is not a mandatory requirement, so other solutions are acceptable.

The problem I'm facing is that when I try to execute the method
FileStream fs = File.OpenRead(@"D:\folder")
I get an error because of access to the specifided path.

How can I zip these files in a simple way?


DotNetZip is much easier to use than SharpZipLib, example of zipping all files in folder :

  using (ZipFile zip = new ZipFile())
    zip.AddDirectory(@"MyDocuments\ProjectX", "ProjectX");

This is a an example from this page :