有关IE中直接打开word、excel、pdf等文档(是直接打开不需要下载提示,也不需要客户端修改IE安全设置)

j_lei407 2009-04-01 11:23:57
孟老大
在客户端浏览各类文档,使用超链接方式,文件流方式都会有下载提示,我希望在IE中直接打开,没有下载提示如何实现?谢谢!下面是我目前使用的代码

string path = Server.MapPath(fileInfo_Path);
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
byte[] MyData = new byte[fileStream.Length];
fileStream.Read(MyData, 0, System.Convert.ToInt32(fileStream.Length));
fileStream.Close();

this.Response.Clear();
this.Response.ClearHeaders();
this.Response.Buffer = true;
this.Response.ContentType = contentType;
this.Response.Expires = -1;
this.Response.AppendHeader("Content-Language", "zh");
this.Response.AppendHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode(file_name, System.Text.Encoding.UTF8));
Response.ContentEncoding = System.Text.Encoding.Default;
this.Response.BinaryWrite(MyData);
this.Response.Flush();
this.Response.End();
...全文
938 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
j_lei407 2009-04-02
  • 打赏
  • 举报
回复
oyljerry,具体怎么做?
oyljerry 2009-04-02
  • 打赏
  • 举报
回复
这个IE总会弹出那个下载提示的,除非自己修改IE的DownloadManager,替代自己的,然后捕捉这个弹出对话框操作,然后直接使用对话框中的Open方式...
j_lei407 2009-04-02
  • 打赏
  • 举报
回复
顶……
j_lei407 2009-04-01
  • 打赏
  • 举报
回复
自己顶一下……在线等待
孟老大……
junyi2003 2009-04-01
  • 打赏
  • 举报
回复
不可能的,不然就是IE漏洞。被黑客攻击的对象。
接分
  • 打赏
  • 举报
回复
分给我吧
j_lei407 2009-04-01
  • 打赏
  • 举报
回复

string path = Server.MapPath(fileInfo_Path);
FileInfo DownloadFile = new FileInfo(path);
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.Buffer = true;
this.Response.ContentType = contentType;
this.Response.Expires = -1;
this.Response.AppendHeader("Content-Language", "zh");
this.Response.AppendHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode(file_name, System.Text.Encoding.UTF8));
Response.ContentEncoding = System.Text.Encoding.Default;
this.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
this.Response.WriteFile(DownloadFile.FullName);
this.Response.Flush();
this.Response.End();

我这样写也是有下载提示
j_lei407 2009-04-01
  • 打赏
  • 举报
回复
继续等待中……

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧