public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> test = new List<string>()
{
"2013-10-09.txt",
"2013-10-10.txt",
"2013-10-11.txt"
};
ZipFiles(test,Request.PhysicalApplicationPath + "test2\\aaa1.zip");
}
public static void ZipFiles(List<string> paths, string savePath)
{
using (ZipFile zip = new ZipFile(savePath))
{
Directory.SetCurrentDirectory(HttpContext.Current.Request.PhysicalApplicationPath + "test\\");// 临时切换到当前目录
foreach (string filePath in paths)
{
zip.AddFile(filePath);
}
Directory.SetCurrentDirectory(Directory.GetCurrentDirectory()); // 恢复当前目录
zip.Save();
}
}
}
压缩文件(压缩路径只包含文件)
最新推荐文章于 2023-11-18 11:40:25 发布