如何在asp.net framework 4.0中压缩/解压缩文件夹
本文关键字:压缩 解压缩 文件夹 asp net framework | 更新日期: 2023-09-27 18:16:34
我使用asp.net 4.0框架,我从我的页面生成pdf文件,并将这些pdf文件存储在文件夹中,在我的应用程序中。现在应用程序的大小变得太大了,所以我想压缩pdf文件的文件夹并下载那个文件夹。请告诉我如何用c#压缩/解压缩一个文件夹
压缩数据卷的一种方法是从该目录生成一个.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