.NET拉链拉上文件拉链、拉上、文件、NET

2023-09-02 10:38:31 作者:我哭过或许软弱-

请告诉我使用C#来压缩的文件的最好方法?理想情况下我希望能够以单独的文件到一个压缩文件。

Whats the best way to zip up files using C#? Ideally I want to be able to seperate files into a single archive.

推荐答案

您可以使用 DotNetZip 以archieve这一点。 It's自由在任何应用程序中使用。

You can use DotNetZip to archieve this. It´s free to use in any application.

Here's一些示例code:

Here´s some sample code:

   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);
   }