【发布时间】: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
提前致谢
【问题讨论】: