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