强制浏览器以完整的单词而不是Word插件打开DOCX文件

时间:2013-11-26 09:30:24

标签: c# asp.net iis web

我有一个Web应用程序,当用户使用单词plug in点击文档在浏览器中打开的链接时,会在目录中列出DOCX文件。是否可以强制浏览器以完整的单词打开文档插入一词?

此应用程序在公司网络上运行,我无法修改机器上的任何设置,只能从网络服务器进行。

他们目前正在使用IE6,几个月后浏览器升级尚未到期。

我怀疑答案是不能做到的。

1 个答案:

答案 0 :(得分:1)

我有类似的问题。我使用Generic Handler实现了解决方案。

为您的项目添加新的GeneriChandler.cs,并在ProcessRequest中执行此代码:

//Search for the file by querystring or other method you did, like name.
string fileId = context.Request.QueryString["fileId"];
FileInfo file = new FileInfo("C:\\" + fileId + ".docx");                
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
context.Response.AddHeader("Content-Length", file.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.WriteFile(file.FullName);

因此,如果您的处理程序被称为MyHandler.ashx,您可以在链接中调用该文件:

<a href="MyHandler.ashx?fileId=1">File 1</a>