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

前端 未结 8 1843
感情败类
感情败类 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:25

    DotNetZip is very simple to use. I like it because it is fully-managed - no shell interaction required. The programming model is simpler and cleaner than that for the shell. Also it is simpler than SharpZipLib as well as the Packaging classes added in .NET 3.0. It is free, small, actively maintained.

    It is much better than the J# option that one poster offered - J# is a huge runtime and a giant pill to swallow to get just ZIP support. Also J# support is being discontinued. Probably not a good idea to introduce new dependencies on J#.

    Example code for DotNetZip:

      try
      {
          using (ZipFile zip = new ZipFile(args[0], System.Console.Out))
          {
              zip.AddDirectory(args[1]); // recurses subdirectories
              zip.Save();
          }
      }
      catch (System.Exception ex1)
      {
          System.Console.Error.WriteLine("exception: " + ex1);
      }
    

    DotNetZip works with .NET v2.0, 3.0, 3.5 as well as Compact Framework v2.0 and 3.5. It does ZIP files, Unicode filenames, comments, passwords. It does ZIP64 as well as Self-extracting archives. It's FAST. Try it.

提交回复
热议问题