c# 压缩 解压 7z
利用7z.dll进行压缩和解压代码如下:
using System; using SevenZip.Sdk; using SevenZip.Sdk.Compression; using SevenZip; using System.IO; namespace DCRM.Common { public class CompressorHelper { public static void Compressor( string p_7zdllPath, string compressDicrectoryName) { SevenZipCompressor.SetLibraryPath(p_7zdllPath); SevenZipCompressor tmp = new SevenZipCompressor(); string fileName=Path.GetDirectoryName(compressDicrectoryName)+ ".7z" ; tmp.CompressDirectory(compressDicrectoryName,fileName); } public static void UnCompressor( string p_7zdllPath, string compressFilesFullName, string des) { SevenZipExtractor.SetLibraryPath(p_7zdllPath); using (SevenZipExtractor tmp = new SevenZipExtractor(compressFilesFullName)) { for ( int i = 0; i < tmp.ArchiveFileData.Count; i++) { tmp.ExtractFiles(des, tmp.ArchiveFileData[i].Index); } } } } } |