/// <summary>
/// 压缩文件为ZIP
/// </summary>
/// <param name="zipPath">压缩文件的地址数组</param>
/// <returns>压缩后文件名</returns>
public string CompressedZip(ArrayList arrFileName)
{
string savePath="F://文件夹的名称";<自己定义>
//压缩包的文件名(本处以时间命名)
string zipName = DateTime.Now.ToString().Replace(" ", "").Replace(":", "") + ".zip";
try
{
//创建压缩文件包
ZipOutputStream s = new ZipOutputStream(File.Create(savePath+ zipName));
s.SetLevel(5);
foreach (string file in arrFileName)
{
FileStream fs = File.OpenRead(savePath + file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(file);
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
fs.Close();
}
s.Finish();
s.Close();
}
catch (Exception ex)
{
Utils.throwErrorBack(@"压缩文件(ZIP)时出错,访问路径:" + savePath + "," + ex.Message);
}
return zipName;
}
注:此压缩方法需要引进一个DLL文件,这个文件可以去网上下载。
<帮助别人等于帮助自己>