C# 为什么可以';我是否使用TransmitFile在浏览器中打开xls文件?

C# 为什么可以';我是否使用TransmitFile在浏览器中打开xls文件?,c#,C#,我使用Response.TransmitFile()打开.XLS/.DOC/.PDF文件。将打开PDF,但XLS-和DOC文件未打开 string path = @"D:\\Files\\" + Request.QueryString.Get("PSFname"); int startIndex = Request.QueryString.Get("PSFname").IndexOf("."); string type = Request.QueryString.Get("PSFname").

我使用
Response.TransmitFile()
打开
.XLS/.DOC/.PDF
文件。将打开
PDF
,但
XLS
-和
DOC
文件未打开

string path = @"D:\\Files\\" + Request.QueryString.Get("PSFname");

int startIndex = Request.QueryString.Get("PSFname").IndexOf(".");
string type = Request.QueryString.Get("PSFname").Substring(startIndex + 1);

if (type == "doc" || type == "docx")
{
    Response.ContentType = "application/ms-word";
}
else if (type == "xls" || type == "xlsx")
{
    Response.ContentType = "application/x-msexcel";
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + Request.QueryString.Get("PSFname"));

}
else if (type == "pdf" || type == "PDF")
{
    Response.ContentType = "Application/pdf";
}
Response.TransmitFile(path);

在这里,您可以在浏览器中打开PDF文件,因为您在浏览器中添加了PDF文件加载项,可以在浏览器中为您打开PDF文件


但是对于Word和Excel文件,没有任何相同的附加组件。所以这些文件不会在浏览器中打开。

您收到任何错误或异常吗?如何打开您的文件?没有xls文件下载但在浏览器上未打开您的意思是您可以下载文件但不能在浏览器中打开文件吗?@ManishParakhiyaexactly@HiralNayak你有XLS和DOC文件的浏览器插件吗?否则,浏览器将不知道如何处理它们。现在,在浏览器中打开Excel文件的解决方案是什么?您必须找到相应的插件。但这只适用于具有该插件的浏览器。@当我使用Internet Explorer时,打开弹出窗口请求保存文件,或打开但不适用于google chrome