asp.net文件和文件夹压缩
调用类库ICSharpCode.SharpZipLib.dll
using System.IO;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
protected void Button1Click(object sender, EventArgs e)
{
string[] str = new string[1];
str[0] = @"E:\9541241560\地学院\";
Zip(str);
}
#region 压缩
///
/// 压缩文件,默认目录为当前目录,文件名为当前目录名,压缩级别为6
///
/// 要压缩的文件或文件夹
public void Zip(params string[] fileOrDirectory)
{
Zip(6, fileOrDirectory);
}
///
/// 压缩文件,默认目录为当前目录,文件名为当前目录名
///
/// 压缩的级别
/// 要压缩的文件或文件夹
public void Zip(int zipLevel, params string[] fileOrDirectory)
{
if (fileOrDirectory == null)
return;
else if (fileOrDirectory.Length < 1)
return;
else
{
string str = fileOrDirectory[0];
if (str.EndsWith("\\"))
str = str.Substring(0, str.Length - 1);
str += ".zip";
Zip(str, zipLevel, fileOrDirectory);
}
}
///
/// 压缩文件,默认目录为当前目录
///
/// 压缩后的文件
/// 压缩的级别
/// 要压缩的文件或文件夹
public void Zip(string zipedFileName, int zipLevel, params string[] fileOrDirectory)
{
if (fileOrDirectory == null)
return;
else if (fileOrDirectory.Length < 1)
return;
else
{
string str = fileOrDirectory[0];
if (str.EndsWith("\\"))
str = str.Substring(0, str.Length - 1);
str = str.Substring(0, str.LastIndexOf("\\"));
Zip(zipedFileName, str, zipLevel, fileOrDirectory);
}
}
///
/// 压缩文件
///
/// 压缩后的文件
/// 压缩的级别
/// 当前所处目录
/// 要压缩的文件或文件夹
public void Zip(string zipedFileName, string currentDire
1