html A标签 href 如何实现下载 图片。 html图片标签 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个是显示图片,因为浏览器认识png的格式,自动做显示处理了你需要后台写一个输出二进制格式图片文件流,并且指定contenttype为<meta http-equiv="Content-Disposition" content="attachment;"> 如果是你自己的站点通过 IHttpModule /// <summary> /// 在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生(4.5、4、3.5、3.0、2.0、1.1、1.0)。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PostRequestHandlerExecuteEvent(object sender, EventArgs e) { HttpApplication ha = (HttpApplication)sender; string filePath = ha.Request.FilePath; if (filePath.Contains(".") && filePath.Remove(0, filePath.LastIndexOf('.')) == ".png") { using (FileStream fs = new FileStream(ha.Server.MapPath(filePath), FileMode.Open, FileAccess.Read)) { int fslength = (int)fs.Length; byte[] b = new byte[fslength]; fs.Read(b, 0, fslength); ha.Response.ContentType = "application/octet-stream"; ha.Response.Write(b); ha.Response.Flush(); ha.Response.End(); } } }<html><head></head><body><img src="http://stimgcn1.s-msn.com/msnportal/hp/2012/10/18/b24b7623-cddc-408d-a01a-c6c3582a612b.png" /><a target="_blank" href="http://stimgcn1.s-msn.com/msnportal/hp/2012/10/18/b24b7623-cddc-408d-a01a-c6c3582a612b.png" >测试图片下载!</a></body></html> 如果你用 IHttpModule 那是不是可以在 web.config中配置那。 /// <summary> /// 文件下载 /// </summary> /// <param name="s_fileName"></param> public static void downloadfile(string s_fileName) { HttpContext.Current.Response.ContentType = "application/ms-download"; string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName; System.IO.FileInfo file = new System.IO.FileInfo(s_path); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream"); HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8)); HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString()); HttpContext.Current.Response.WriteFile(file.FullName); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.End(); }后台onclick调用就行了. 不用,C# 的, C# 的 代码满天飞。我的意思是直接加 http-equiv 的方式 refer : http://blog.csdn.net/awinliu/article/details/9401083 大神们,问下,我把<meta http-equiv="Content-Disposition" content="attachment;"> 这句放在前台,后台写的如下 result += @"<ul> <li style='width:400px;' > <a target='_blank' href='../upload/UserInfo/" + inside.Inside_number + @"/" + name + @"/" + info.Name + @"'" + @">" + info.Name + @"</li> <li style='width:117px;'> <a target='_blank' href='../upload/UserInfo/" + inside.Inside_number + @"/" + name + "/" + info.Name + "'" + @">下载</a>" + @"</li>这样下载图片还是不行啊,那这样应该如何做啊? 使用IIS Web服务器 选项是在哪里的? 求Jquery、js弹出层,或者页面 如何通过三个标签按钮将三个页面分别显示在同一个div区域里?代码如何写? 谢谢赐教 如何删除上传后不合要求的图片,有一个进程占用着刚才那图片! 利用odbc连接dbf文件的问题,请大家帮忙!! 谁能给个table显示数据库内容的例子,`或者讲讲也好。谢谢。 我在自己机器上调好了ASP.NET程序,怎么让它在我同学机器上用起来啊? 菜鸟问一个onclick的问题 求助:VS.NET 中新建WEB解决方案是提示错误。 高分请教 关于 @Html.CheckBox asp.net怎么实现exe格式的文件下载?
contenttype为
<meta http-equiv="Content-Disposition" content="attachment;">
通过 IHttpModule
/// <summary>
/// 在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生(4.5、4、3.5、3.0、2.0、1.1、1.0)。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PostRequestHandlerExecuteEvent(object sender, EventArgs e)
{
HttpApplication ha = (HttpApplication)sender; string filePath = ha.Request.FilePath; if (filePath.Contains(".") && filePath.Remove(0, filePath.LastIndexOf('.')) == ".png")
{
using (FileStream fs = new FileStream(ha.Server.MapPath(filePath), FileMode.Open, FileAccess.Read))
{
int fslength = (int)fs.Length;
byte[] b = new byte[fslength];
fs.Read(b, 0, fslength);
ha.Response.ContentType = "application/octet-stream";
ha.Response.Write(b);
ha.Response.Flush();
ha.Response.End();
}
}
}<html>
<head>
</head>
<body>
<img src="http://stimgcn1.s-msn.com/msnportal/hp/2012/10/18/b24b7623-cddc-408d-a01a-c6c3582a612b.png" />
<a target="_blank" href="http://stimgcn1.s-msn.com/msnportal/hp/2012/10/18/b24b7623-cddc-408d-a01a-c6c3582a612b.png" >测试图片下载!</a>
</body>
</html>
/// <summary>
/// 文件下载
/// </summary>
/// <param name="s_fileName"></param>
public static void downloadfile(string s_fileName)
{
HttpContext.Current.Response.ContentType = "application/ms-download";
string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName;
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}后台onclick调用就行了.
result += @"<ul>
<li style='width:400px;' >
<a target='_blank' href='../upload/UserInfo/" + inside.Inside_number + @"/" + name + @"/" + info.Name + @"'" + @">" + info.Name + @"</li>
<li style='width:117px;'>
<a target='_blank' href='../upload/UserInfo/" + inside.Inside_number + @"/" + name + "/" + info.Name + "'" + @">下载</a>" + @"</li>
这样下载图片还是不行啊,那这样应该如何做啊?