今天遇到一个功能要实现图片的下载,最先想到的办法就是a标签来进行下载,但是坑爹的是href指向图片路径后点击的效果是浏览器打开,后来在网上也查找了不少的方法,但是依旧没成功,最好不得不使用后台生成的方法 代码很简单
1
2
3
4
5
6
7
8
9
10
11 |
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); } |
原文:http://www.cnblogs.com/Rock-Lee/p/3512988.html