string fileName = "test.zip";
string path = "c:\\temp\\";
string fullPath = path + fileName;
FileInfo file = new FileInfo(fullPath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
Response.AppendHeader("content-length", file.Length.ToString());
Response.ContentType = "application/x-compressed";
Response.TransmitFile(fullPath);
Response.Flush();
Response.End();
實際的壓縮文件c:\ temp \ test.zip是好的,有效的,無論您想調用它。當我導航到目錄c:\ temp \並雙擊test.zip文件時;它正確地打開。ASP.NET創建zip文件進行下載:壓縮的壓縮文件夾無效或損壞
我的問題似乎只與下載。上面的代碼執行沒有任何問題。提供文件下載對話框。我可以選擇保存或打開。如果我嘗試從對話框中打開文件,或保存並打開它。我收到以下對話框消息:
壓縮(壓縮)文件夾無效或損壞。
對於Response.ContentType我試着:
應用程序/ x壓縮 應用程序/ x-ZIP壓縮 應用程序/ x-用gzip compresse 應用/八位字節流 應用程序/壓縮
Ionic.ziphttp://www.codeplex.com/DotNetZip
:使用的zip文件正在被一些現有的代碼創建了(我敢肯定,工作正常,由於我直接打開所創建的文件的能力)
只是一個預感,下載的文件是否與原始大小相同? – CResults 2010-03-16 18:22:30