如何使用C#在asp.net 2010中下载 [英] how to download in asp.net 2010 with c#

查看:69
本文介绍了如何使用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 :)


这篇关于如何使用C#在asp.net 2010中下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆