.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);
    }

  

posted on 2014-01-10 00:10  奋斗的笨小孩  阅读(552)  评论(0编辑  收藏  举报