【问题标题】:Issue opening doc/docx/excel files in browser(Asp.net, C#)在浏览器中打开 doc/docx/excel 文件的问题(Asp.net,C#)
【发布时间】:2023-03-28 15:29:01
【问题描述】:

我正在文件系统中存储一些文件,例如 PDF、Doc、Docx、xls 等。

现在我必须在浏览器上显示这些文件以供用户查看。

所以基本上数据网格中有一个链接按钮,点击后用户将能够查看。

到目前为止,我的代码是这样的

Response.Clear();

// Response.ContentType = "application/pdf";
//Response.ContentType = "application/x-msexcel";       
//Response.ContentType = "application/msword";

string strFilePath = @"C:\test.pdf";
// string strFilePath = @"C:\test.doc";

Response.WriteFile(strFilePath);
Response.End();

这适用于 pdf 文件,但不适用于 word 或 excel 文件。在浏览器中,我可以查看 pdf,但其他文件未在浏览器中打开,但要求

Save , Open 对话框选项。如果我点击Open,它将在普通窗口而不是浏览器中打开。

我怎样才能实现我的目标?浏览器是IE

提前致谢

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    你试过添加这样的东西吗?

    Response.AppendHeader("Content-Disposition", "inline;filename=" + "ExcelFile.xls");
    

    【讨论】:

      【解决方案2】:

      可能存在浏览器配置问题。

      尝试更改浏览器中的一些设置(自定义级别)。

      1. 在 iframe 中启动程序和文件
      2. 正在启动应用程序和不安全的文件。

      【讨论】:

        猜你喜欢
        • 2021-08-30
        • 2010-12-06
        • 2012-08-13
        • 1970-01-01
        • 1970-01-01
        • 2011-04-21
        • 1970-01-01
        • 1970-01-01
        • 2014-03-01
        相关资源
        最近更新 更多