有没有办法当鼠标点击链接后,出现下载的对话框? 想实现这样的功能,数据库中有一个文件的真实名称(别人上传时的名),还有一个自动生成的名,然后当别人点击链接后,会出现另存为(真实名称)文件的一个对话框。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 =========public static bool DownloadAttachment(string filePath) { try { FileInfo file = new FileInfo(filePath); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.Buffer = false; string strHadFileName = System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes(file.Name)); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strHadFileName); HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString()); string strFullName = file.FullName; HttpContext.Current.Response.WriteFile(strFullName); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } catch { return false; } return true; } >> HttpContext.Current.Response.ContentType = "application/octet-stream";这句话可能要修改:HttpContext.Current.Response.ContentType = "application/x-download"; 日期格式验证 2011-09-27 格式 关于日志类 SQL Server中表dtA是表dtB和表dtC的主键表,请问高手几个问题 为什么我的Cookies修改不了 求AJAX入门的电子书,谢谢! petshop版本3对版本2的更改,为什么要把所有静态方法改为实例方法? 如何设计 Schema , 会有利于日后的扩充?? 用户自定义控件的问题 chrome 的 try catch 的问题 有做过论坛或者贴吧大神,以及有建议灌水的请进 新手请教:ASP.net连接access数据库错误!说是没有权限! 呱呱,大家在工作,写程序的时候都爱听什么音乐呀,给推荐一下.
public static bool DownloadAttachment(string filePath)
{
try
{
FileInfo file = new FileInfo(filePath);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = false;
string strHadFileName = System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes(file.Name));
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strHadFileName);
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
string strFullName = file.FullName;
HttpContext.Current.Response.WriteFile(strFullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
catch
{
return false;
}
return true;
}
这句话可能要修改:HttpContext.Current.Response.ContentType = "application/x-download";