我打開.XLS/.DOC/.PDF
文件與Response.TransmitFile()
。 PDF
被打開,但XLS
-和DOC
文件未打開。爲什麼我無法使用TransmitFile在瀏覽器中打開xls文件?
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);
您收到任何錯誤或異常?你如何打開你的文件? – 2014-12-05 07:51:17
沒有xls文件下載,但沒有在瀏覽器上打開 – 2014-12-05 07:51:57
你的意思是你可以下載文件但不能在瀏覽器中打開文件? – 2014-12-05 08:56:14