.Net文件压缩
NuGet中下载Ionic.Zip:
public static class ZipHelper { /// <summary> /// 压缩文件 /// </summary> /// <param name="FileFolder">要压缩的文件夹地址</param> /// <param name="File">压缩后的新文件</param> /// <returns>true成功,false失败</returns> public static bool Zip(string FileFolder, string File) { try { using (ZipFile zip = new ZipFile()) { zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default; zip.AddDirectory(FileFolder); zip.Save(File); } return true; } catch (Exception) { return false; } } /// <summary> /// 解压文件 /// </summary> /// <param name="File">要解压的文件</param> /// <param name="FileFolder">压缩后的文件夹地址</param> /// <returns>true成功,false失败</returns> public static bool UnZip(string File, string FileFolder) { try { using (ZipFile zip = new ZipFile(File)) { zip.ExtractAll(FileFolder); } return true; } catch (Exception) { return false; } } }