What is the best/easiest way to create ZIP archive in .NET?

前端 未结 8 1815
感情败类
感情败类 2020-12-07 17:39

Which method do you think is the \"best\".

  • Use the System.IO.Packaging namespace?
  • Use interop with the Shell?
  • Third party librar
相关标签:
8条回答
  • 2020-12-07 18:41

    I realise that this is an old question now, but I just thought I'd add a more up to date answer. If you are using .NET 4.5, then you can programmatically save multiple files into a zip folder easily using the new built in ZipFile class.

    First, you'll need to prepare your files into a new folder (Directory.CreateDirectory, File.Move) and then you can simply use the ZipFile.CreateFromDirectory Method (adapted from the linked page):

    string filePathOfNewFolder = @"c:\example\start";
    string zipFilePath = @"c:\example\result.zip";
    
    ZipFile.CreateFromDirectory(filePathOfNewFolder, zipFilePath);
    
    0 讨论(0)
  • 2020-12-07 18:42

    I've found the DotNetZip Library to be this easiest way to work with zip files. SharpZipLib is a far more powerful and flexible solution.

    0 讨论(0)
提交回复
热议问题