[C#]使用 sevenzipsharp 壓縮並維持目錄結構
目前我系統要求壓縮相關選擇檔案和目錄須維持client目錄結構,
今天反覆測試sevenzip終於搞定了,紀錄一下。
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string sevendllpaht = assemblyFolder + "\\lib\\7z.dll";
SevenZipCompressor.SetLibraryPath(sevendllpaht);
using (FileStream fs = new FileStream(@"e:\test.zip", FileMode.Create))
{
SevenZipCompressor szc = new SevenZipCompressor
{
CompressionMethod = CompressionMethod.Deflate,
CompressionLevel = CompressionLevel.Normal,
CompressionMode = CompressionMode.Create,
DirectoryStructure = true,
PreserveDirectoryRoot = false,
ArchiveFormat = OutArchiveFormat.Zip
};
Dictionary<string, string> filesDictionary = new Dictionary<string, string>();
//replace root fullname
filesDictionary.Add(@"點部落格文章\SQL SERVER\recovery using filegroup.docx", @"D:\點部落格文章\SQL SERVER\recovery using filegroup.docx");
filesDictionary.Add(@"點部落格文章\新文字文件.txt", @"D:\點部落格文章\新文字文件.txt");
filesDictionary.Add(@"點部落格文章\SQL SERVER\BI\[SQL SERVER][BI] 多維度報表(1).docx", @"D:\點部落格文章\SQL SERVER\BI\[SQL SERVER][BI] 多維度報表(1).docx");
filesDictionary.Add(@"VSTO學習筆記.txt", @"e:\VSTO學習筆記.txt");
//do not use CompressFiles
szc.CompressFileDictionary(filesDictionary,fs);
MessageBox.Show("ok");
}
結果