2012-07-24 85 views
-1

我嘗試從serverside下載docx文件。 我的錯誤是什麼?爲什麼不能在asp.net中打開下載的docx文件?

這是代碼:

FileInfo file = new FileInfo(filepath); 
     Response.Clear(); 
     Response.ClearHeaders(); 
     Response.ClearContent(); 
     Response.AppendHeader("Content-Disposition", "attachment; filename = " + ((Button)sender).CommandName + ".docx"); 
     Response.AppendHeader("Content-Length", file.Length.ToString()); 
     Response.ContentType = "application/octet-stream"; 
     Response.WriteFile(file.FullName); 
     Response.Flush(); 
     Response.Close(); 
     Response.End(); 
+3

你得到了什麼錯誤? – Marcus 2012-07-24 21:48:30

+0

這是一個正常的asp.net文件,您使用的瀏覽器是?它發生在不同的瀏覽器上嗎? – Graymatter 2012-07-24 21:59:27

+0

我下載了它,但它並沒有在辦公室打開,而我使用chrome – Mennan 2012-07-24 22:03:58

回答

1

我已經張貼在一個PDF另一個問題類似的東西但在這裏不用。通過ASHX處理程序將這種數據流式傳回容易得多。

就像我發佈在這個問題,但與docx文件。

Display PDF in iframe

它看起來像您使用的是普通的ASP.NET頁面,並試圖修改通過清除報頭中的標準行爲,等等。你不會有標題或類似的東西搗鼓用ashx處理程序。

相關問題