Asp.net mvc 2 使用c代码生成zip文件

Asp.net mvc 2 使用c代码生成zip文件,asp.net-mvc-2,Asp.net Mvc 2,我想使用.net framework类从我的mvc.net c#应用程序创建zip文件。 请尽快回复我 使用外部库,如或。 例如,使用DotNetZip,您可以制作如下所示的zip文件: using (ZipFile zip = new ZipFile()) { // add this map file into the "images" directory in the zip archive zip.AddFile("c:\\images\\personal\\744

我想使用.net framework类从我的mvc.net c#应用程序创建zip文件。 请尽快回复我

使用外部库,如或。 例如,使用DotNetZip,您可以制作如下所示的zip文件:

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

你查过了吗?

我用过的第三方库是


与SharpZipLib相比,我更喜欢它——SharpZipLib的布局并不十分直观。

使用.NET 4.5您现在可以使用.NET framework轻松创建zip文件:

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
  class Program
  {
    static void Main(string[] args)
    {
      string startPath = @"c:\example\start";
      string zipPath = @"c:\example\result.zip";
      string extractPath = @"c:\example\extract";

      ZipFile.CreateFromDirectory(startPath, zipPath);

      ZipFile.ExtractToDirectory(zipPath, extractPath);
    }
  }
}
上述代码直接取自Microsoft的文档:


还有其他生成压缩文件的方法,这些方法将在上面链接的页面上进一步解释。

我会选择下面的一个答案,但如果您在一个他们不喜欢第三方DLL的地方工作,我将链接到我今天早些时候对类似问题的回答: