实际的zip文件c:\temp\test.zip是好的,有效的,无论你想叫它当我导航到目录c:\temp\并双击test.zip文件;它直接打开。
The actual zip file c:\temp\test.zip is good, valid, whatever you want to call it. When I navigate to the directory c:\temp\ and double-click on the test.zip file; it opens right up.
我的问题似乎只是下载。上面的代码执行没有任何问题。介绍文件下载对话框。我可以选择保存或打开。如果我尝试从对话框打开文件,或者保存它然后打开它。我收到以下对话框消息:
My problem seems only to be with the download. The code above executes without any issue. A file download dialog is presented. I can chose to either save or open. If I try to open the file from the dialog, or save it and then open it. I get the following dialog message:
压缩(压缩)文件夹无效或损坏。
The Compressed (zipped) Folder is invalid or corrupted.
.ContentType我试过:
For Response.ContentType I've tried:
应用程序/ x压缩应用程序/ x-zip压缩应用程序/ x-gzip-compresse 应用程序/八位字节流应用程序/ zip
application/x-compressed application/x-zip-compressed application/x-gzip-compresse application/octet-stream application/zip
正在使用一些先前的代码创建zip文件(我确定正在工作正常以我的能力直接打开创建的文件)使用:Ionic.zip
The zip file is being created with some prior code (that I'm sure is working fine due to my ability to open the created file directly) using: Ionic.zip
www.codeplex/DotNetZip
推荐答案这个工作。我不知道为什么这样做。
This worked. I don't know why but it did.
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-Cength", file.Length.ToString()); Response.ContentType = "application/x-zip-compressed"; Response.WriteFile(fullPath); //Response.Flush(); Response.End();更多推荐
ASP.NET创建zip文件进行下载:压缩的压缩文件夹无效或损坏
发布评论