【发布时间】:2015-07-14 20:09:52
【问题描述】:
我想使用带有 C# 的 ASP.NET 从网络上的共享文件夹中打开文档。 我的情况如下:
- 我的 Web 服务器名称是“WebServer1”,使用 IIS 7
- 我的 DC 服务器名称是“DC1”
- 我的文件服务器名称“FileServer1”
- 我的文件路径
\\FileServer1\A\B\C\MyDoc.docx和\\FileServer1\A\B\C\MyPDF.pdf
我尝试了以下
1- 我创建了超链接
<a href="file:///// FileServer1\A\B\C\MyDoc.docx" target="_blank">link to file</a>
文件在某些使用 Internet Explorer 版本 8 的机器上打开,但在任何其他版本或 Chrome、Fire Fox 或任何其他网络浏览器上打开,当我单击超链接时它不起作用,没有任何操作发生,也没有错误,但是如果我复制了链接地址并将其粘贴到网络浏览器中,文件就会打开
我将文件服务器中的路径授予“所有人”的完全控制权限
2- 我也尝试使用以下代码创建一个按钮
Response.ContentType =
"application/vnd.openxmlformats- officedocument.wordprocessingml.document";
Response.AppendHeader("Content-Disposition", "attachment; filename=5401-1-2289.docx");
Response.Redirect("file:///// FileServer1\A\B\C\MyDoc.docx");
Response.Flush();
【问题讨论】:
-
file://///在最后一个/之后包含一个空格,对吗? -
使用
Content-Disposition: attachment时,需要将文件写入输出,不能使用Redirect。您可以使用Response.TransmitFile(@"\\FileServer1\A\B\C\MyDoc.docx");之类的东西至于超链接/重定向,它需要用户有权访问共享驱动器,而不是网络服务器。而且它只能在 Outlook / IE / Word 等中运行,按设计 - stackoverflow.com/questions/1369147/…
标签: c# asp.net iis cross-browser