2016-11-07 253 views
0

我使用的是asp.net 4.0框架,我从我的页面生成pdf文件并将这些pdf文件存储在我的应用程序中的文件夹中。现在应用程序的大小变得太大,所以我想压缩该pdf文件的文件夹并下载该文件夹。请建议我如何在c#中压缩/解压缩文件夹。压缩的datavolume如何在asp.net框架4.0中压缩/解压缩文件夹

+0

不知道你在问什么。你想启用文件夹压缩来减少“应用程序的大小”?或者你想允许用户下载你的应用程序生成的PDF文件的ZIP存档? –

+0

你试过了什么?你得到了哪些错误?请查看[how-to-ask](http://stackoverflow.com/help/how-to-ask) – swe

回答

1

一种方法是从生成该目录的.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, CompressionLevel.Fastest, true); 

      ZipFile.ExtractToDirectory(zipPath, extractPath); 
     } 
    } 
} 

在这个例子中,你把你的.pdf文件夹,压缩它,并提取其别的地方使用

CompressionLevel.Fastest, true