相关疑难解决方法(0)

ASP.NET将所有文件下载为Zip

我的网络服务器上有一个文件夹,里面有数百个mp3文件.我想为用户提供从网页下载目录中每个mp3的压缩存档的选项.

我想只在需要时以编程方式压缩文件.因为zip文件会非常大,所以我认为出于性能原因,我需要将zip文件发送到压缩响应流中.

这可能吗?我该怎么做?

.net c# asp.net zip

7
推荐指数
2
解决办法
3万
查看次数

ASP.NET如何将文件流式传输给用户

最初我试图找出Response.Close和Response.End之间的区别,但是在进行了更多的谷歌搜索和研究后,很明显我没有看到Byte []被发送回客户端的常见方式.我将在下面留下代码示例,但我想知道行业标准是做什么的.

Byte[] myBytes = GetReportBytes();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AppendHeader("content-length", myBytes.Length.ToString());
HttpContext.Current.Response.AppendHeader("content-Disposition", "attachment;filename=" + this.ReportFileName + GetReportExtension());
HttpContext.Current.Response.ContentType = GetApplicationContentType();
HttpContext.Current.Response.BinaryWrite(myBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
//CERT FIX
//HttpContext.Current.Response.End();
Run Code Online (Sandbox Code Playgroud)

c# asp.net download httpresponse

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×2

c# ×2

.net ×1

download ×1

httpresponse ×1

zip ×1