.Net Zip Up文件

AJM*_*AJM 10 .net c# zip

什么是使用C#压缩文件的最佳方法?理想情况下,我希望能够将文件分成单个存档.

Jeh*_*hof 14

您可以使用DotNetZip来实现这一目标.它可以在任何应用程序中自由使用.

这是一些示例代码:

   try
   {
     // for easy disposal
     using (ZipFile zip = new ZipFile())
     {
       // add this map file into the "images" directory in the zip archive
       zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
       // add the report into a different directory in the archive
       zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
       zip.AddFile("ReadMe.txt");
       zip.Save("MyZipFile.zip");
     }
   }
   catch (System.Exception ex1)
   {
     System.Console.Error.WriteLine("exception: " + ex1);
   }
Run Code Online (Sandbox Code Playgroud)


Fas*_*tAl 7

如果您有4.5+版本,现在已内置到框架中

否则,使用Ionic.

命名空间是System.IO.Packaging.ZIPPackage.

有关故事,请参见http://visualstudiomagazine.com/articles/2012/05/21/net-framework-gets-zip.aspx.