简体   繁体   中英

Why can't I open xls file in browser using TransmitFile?

I open .XLS/.DOC/.PDF files with Response.TransmitFile() . The PDF get opened, but the XLS -and the DOC files not Open.

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);

Here you can open PDF file in browser because you have Add-On for pdf file added in your browser that opens pdf file for you in browser.

But there is no any Add-On for the same for Word and Excel file. so these file is not opens in browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM