我想使用c#壓縮文件夾中的文件和文件夾,而且我查看了以前提出的問題,但它們不適用於我......我目前正在嘗試與DotNetZip合作。以下是我的代碼:使用c#在一個文件夾中壓縮文件並返回響應
using (ZipFile zip = new ZipFile())
{
string[] files = Directory.GetFiles(@"C:\Users\T1132\Desktop\logs");
// add all those files to the logs folder in the zip file
zip.AddFiles(files, "logs");
zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
var a = System.DateTime.Now.ToString();
zip.Save(@"C:\Users\T1132\Desktop\logs\Archiver.zip");
foreach (var f in files)
{
System.IO.File.Delete(f);
System.Diagnostics.Debug.WriteLine(f + "will be deleted");
}
}
上面的代碼工作,但它只能壓縮文件並保留文件夾。請幫助我,謝謝。
檢查[這個答案](https://stackoverflow.com/a/10643602/4685428) –
請參閱[問]和[MCVE]如何提出好的問題。 DotNetZip遇到的具體問題是什麼?你有什麼嘗試?你卡在哪裏? –