日期:2014-05-18  浏览次数:20368 次

ASP.NET直接打开文档,而不出现下载的提示,求教
<a       target= "_blank "       href= "http://ss/xx.doc "> X </a>  
这是直接弹出对话框询问打开还是下载,能不是直接打开,而不是弹出对话框再选择

------解决方案--------------------
我能想到的就是你将所有的下载都转到一个专有的共同页面,然后在那个页面上进行下载嘛
------解决方案--------------------
doc,pdf什么的支持IE打开的.可以做一个下载页面啊
------解决方案--------------------
to jadezhou83
呵呵,我的意思就是你的a标签的链接url就不要指向具体的下载文件,而是统一的一个下载页面(那个页面上可以构造标签 <a target= "_blank " href= "http://ss/xx.doc "> X </a> )
比如原来你的a 标签所在页面可以
<a target= "_blank " href= "http://ss/xx.aspx?fileid= "+param> X </a>
//param是下载文件的唯一标识
然后统一下载页面(xx.aspx)就可以通过fileid来构造出以下标签,用户点击就可以实现你的要求了
<a target= "_blank " href= "http://ss/xx.doc "> X </a>
------解决方案--------------------
如果是文本的话,用连接只能打开,不能出现下载对话框的
你用下面的试试
我在做上传下载的时候用的:
System.IO.FileInfo objFileInfo;
if (System.IO.File.Exists(PhysicalPath))
{
objFileInfo = new System.IO.FileInfo(PhysicalPath);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.AddHeader( "Content-Disposition ", "attachment;filename= " + objFileInfo.Name);
System.Web.HttpContext.Current.Response.AddHeader( "Content-Length ", objFileInfo.Length.ToString());
System.Web.HttpContext.Current.Response.ContentType = FileType;
System.Web.HttpContext.Current.Response.WriteFile(objFileInfo.FullName);
System.Web.HttpContext.Current.Response.End();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "a ", " <Script> alert( '文件不存在! '); </Script> ");
}

PhysicalPath 下载文件的路径
FileType 下载文件的类型
------解决方案--------------------
可以装个文裆查件,就不用从本地掉了!
------解决方案--------------------
用Response输出来
注意文件类型
------解决方案--------------------
点下面的管理