.Net Zip Up files

后端 未结 6 1327
不思量自难忘°
不思量自难忘° 2020-12-06 02:38

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

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 02:41

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

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

提交回复
热议问题