How to compress a directory into a zip file programmatically

后端 未结 4 910

I want to compress an entire directory which can have any number of subdirectories into a single ZIP file.

I am able to compress a single file into a zip file progra

相关标签:
4条回答
  • 2020-12-15 07:49

    Using DotNetZip, there's an AddDirectory() method on the ZipFile class that does what you want:

    using (var zip = new Ionic.Zip.ZipFile())
    {
        zip.AddDirectory("DirectoryOnDisk", "rootInZipFile");
        zip.Save("MyFile.zip");
    }
    

    This example, and many others, are available on codeplex.

    0 讨论(0)
  • 2020-12-15 07:55

    You can see Article about Zip / Unzip folders and files with C#.

    0 讨论(0)
  • 2020-12-15 08:00

    Take a look at one of these API's:

    • DotNetZip
    • SharpZipLib
    0 讨论(0)
  • 2020-12-15 08:00
    ZipFile.CreateFromDirectory(<path of folder you need to zip>, <path of zip file with .zip in the end>, CompressionLevel.Fastest, true);
    
    0 讨论(0)
提交回复
热议问题