.NET实现图片下载(后台)

    今天遇到一个功能要实现图片的下载,最先想到的办法就是a标签来进行下载,但是坑爹的是href指向图片路径后点击的效果是浏览器打开,后来在网上也查找了不少的方法,但是依旧没成功,最好不得不使用后台生成的方法 代码很简单

   protected void lbtn_load_Click(object sender, EventArgs e)
    {
        string path = Request.QueryString["path"] == null ? null : Request.QueryString["path"].ToString();
        path = path.Substring(3, path.Length - 3);
        Response.ContentType = "application/x-msdownload";
        //下载的图片名
        string filename = "attachment; filename=" + "tupian.jpg";
        Response.AddHeader("Content-Disposition", filename);
        string filepath = path;
        Response.TransmitFile(filepath);
    }

  

原文地址:https://www.cnblogs.com/Rock-Lee/p/3512988.html