ASP.NET创建下载的zip文件:pssed压缩文件夹中的COM $ P $是无效或损坏 [英] ASP.NET Create zip file for download: the compressed zipped folder is invalid or corrupted
问题描述
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();
实际的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.
我的问题似乎只与下载。在code以上的执行没有任何问题。文件下载对话框是presented。我可以选择保存或打开。如果我尝试从对话框中打开文件,或保存它,然后打开它。我碰到下面的对话框消息:
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:
pssed在COM $ P $(zipped)文件夹是无效或已损坏。
The Compressed (zipped) Folder is invalid or corrupted.
有关Response.ContentType我试过:
For Response.ContentType I've tried:
应用程序/ x-COM pressed
应用程序/ x-ZIP-COM pressed
应用程序/ x-gzip的-COM preSSE
应用程序/八位字节流
应用程序/压缩
application/x-compressed application/x-zip-compressed application/x-gzip-compresse application/octet-stream application/zip
该zip文件与一些以前的code。使用创建(我敢肯定,工作正常,由于我直接打开创建的文件的能力):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
HTTP://www.$c$cplex.com/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文件:pssed压缩文件夹中的COM $ P $是无效或损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!