C# 四种实现文件下载
2009 年 12 月 21 日 星期一 上午 11:58
using System;
using System.Data;
using System.Conguration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//TransmitFile 实现下载
protected void Button1_Click(object sender, EventArgs e)
{
/*
微软为 Response 对象提供了一个新的方法 TransmitFile 来解决使用
Response.BinaryWrite
下载超过 400mb 的文件时导致 Aspnet_wp.exe 进程回收而无法成功下载的
问题。
代码如下:
*/
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition",
"attachment;lename=z.zip");
string lename = Server.MapPath("DownLoad/z.zip");
Response.TransmitFile(lename);
}
//WriteFile 实现下载
protected void Button2_Click(object sender, EventArgs e)
{
/*
using System.IO;
评论2