當我有這個小碼:空的檔案壓縮與ZipForge多個文件和C#
HttpContext.Current.Response.Clear();
if (files.Contains(',')) {
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader("content-disposition", "filename=arch-01.zip");
string[] split = files.Split(',');
ZipForge zip = new ZipForge();
try {
zip.FileName = Path.Combine(@"C:\Item", "arch-01.zip");
zip.OpenArchive(System.IO.FileMode.Create);
zip.BaseDir = @"C:\";
foreach (string file in split) {
zip.AddFiles(file);
}
zip.CloseArchive();
} catch (Exception e) {
Console.Write(e.Message);
}
}
壓縮,顯示在瀏覽器Open - Save As
對話框後,我想。該文件存在,我們假設files
包含
C:\Item\a1.xls,C:\Item\a2.xls.
但歸檔是空的,永遠。我的錯誤在哪裏?我有C:的許可。 我在響應頭錯了嗎?
HttpContext.Current.Response.WriteFile(zip.FileName);
和現在的作品:)
我知道'attachment',但它不工作無論如何 – 2012-03-14 07:11:18