2014-12-05 43 views
0

我打開.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); 
+0

您收到任何錯誤或異常?你如何打開你的文件? – 2014-12-05 07:51:17

+0

沒有xls文件下載,但沒有在瀏覽器上打開 – 2014-12-05 07:51:57

+0

你的意思是你可以下載文件但不能在瀏覽器中打開文件? – 2014-12-05 08:56:14

回答

1

在這裏,您可以在瀏覽器中打開PDF文件,因爲你必須添加爲在瀏覽器中添加的PDF文件,在瀏覽器中打開PDF文件給你。

但是對於Word和Excel文件,沒有相同的附加組件。所以這些文件不會在瀏覽器中打開。

+0

現在什麼是在瀏覽器中打開Excel文件的解決方案 – 2014-12-05 09:01:42

+0

你必須找到相應的插件。但這隻適用於擁有該插件的瀏覽器。 – 2014-12-05 09:02:56

+0

@when我使用Internet Explorer然後打開彈出窗口詢問保存文件或打開但不適用於谷歌瀏覽器 – 2014-12-05 09:24:25

相關問題