ASP.NET创建zip文件进行下载:压缩的压缩文件夹无效或损坏

编程入门 行业动态 更新时间:2024-10-20 07:47:00
本文介绍了ASP.NET创建zip文件进行下载:压缩的压缩文件夹无效或损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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.

我的问题似乎只是下载。上面的代码执行没有任何问题。介绍文件下载对话框。我可以选择保存或打开。如果我尝试从对话框打开文件,或者保存它然后打开它。我收到以下对话框消息:

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文件进行下载:压缩的压缩文件夹无效或损坏

本文发布于:2023-11-12 04:08:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580479.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进行下载   文件夹   文件   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!