c# 压缩文件夹两种方法:
1.需要引入Ionic.Zip.dll,没有的安装nuget包
string toFilePath = "";//生成到哪里
stiring zipFilePath = "";//待压缩的文件夹
var pathList = new List<stirng>();
pathList.add(zipFilePath);//需要压缩的所有文件夹
using(ZipFile zip = new ZipFile(toFilePath, Encoding.Defauft))
{
foreach(var path in pathList)
{
string fileName = System.IO.Path.GetFileName(path);
string curDir = Directory.GetCurrnetDirectory();
Directory.SetCurrentDirectory(toFilePath);
zip.addDirectory(path);
Directory.SetCurrentDirectory(curDir);
}
zip.Save(tofilePath + "文件名.zip");
return tofilePath + "文件名.zip";
}
2. 需要net framework4.5以上版本,简单易操作
链接:https://jingyan.baidu.com/article/3f16e00313a8a72591c10313.html
c#同时压缩多个文件:c# zip压缩多个文件_阿道的专栏-CSDN博客