码迷,mamicode.com
首页 > 其他好文 > 详细

下载指定路径下的图片案例,源代码

时间:2015-02-14 16:07:20      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

#region 下载珠宝图片
protected void lbtnDown_Click(object sender, EventArgs e)
{
int pid = ConvertHelper.GetInteger(Request["PID"]);
pds = p.GetModel(pid);
// 保存文件的虚拟路径
string Url = "../uploadpic\\" + pds.Picture;//<img src="../uploadpic/20150213/wm201521317692.jpg" />
// 保存文件的物理路径
string FullPath = HttpContext.Current.Server.MapPath(Url);
// 初始化FileInfo类的实例,作为文件路径的包装
FileInfo FI = new FileInfo(FullPath);
// 判断文件是否存在
if (FI.Exists)
{
// 将文件保存到本机
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(FI.Name));
Response.AddHeader("Content-Length", FI.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(FI.FullName);
Response.End();
}
}

#endregion

下载指定路径下的图片案例,源代码

标签:

原文地址:http://www.cnblogs.com/azzhang/p/4291854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!