如何使用C#在asp.net 2010中下载
问题描述:
如何使用按钮单击在asp.net2010 c#中下载文件
how to download a file in asp.net2010 c# using a button click
答
Herez代码在按钮单击事件中下载ASP.NET中的文件名为``btnDowmLoad_Click''
Herez the code to download a file in ASP.NET on a button click event named as ''btnDowmLoad_Click''
protected void btnDowmLoad_Click(object sender, EventArgs e)
{
try
{
string strURL=txtFileName.Text;
WebClient req=new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer= true;
response.AddHeader("Content-Disposition","attachment;filename=\"" + Server.MapPath(strURL) + "\"");
byte[] data=req.DownloadData(Server.MapPath(strURL));
response.BinaryWrite(data);
response.End();
}
catch(Exception ex)
{
}
}
尝试一下:
在ASP.NET中下载文件并跟踪状态下载成功/失败的原因 [ ^ ]
希望对您有所帮助:)
try this:
File Download in ASP.NET and Tracking the Status of Success/Failure of Download[^]
hope it helps :)