.NET拉链拉上文件 [英] .Net Zip Up files

查看:228
本文介绍了.NET拉链拉上文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我使用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);
   }

这篇关于.NET拉链拉上文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆