2011-11-16 52 views
2

我出口從一個excel文件 「C:測試\ data.xls」 使用性反應的對象 像:導出Excel文件,不用其他任何對話框+ asp.net,C#

response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";"); 

是開口對話框。但現在我們不需要對話框了。我們想直接打開沒有對話框的文件。 任何機構可以幫助我

回答

0

而不是將文件附加到響應您將它的內容寫入響應流。

//Set the appropriate ContentType. 
Response.ContentType = "application/vnd.ms-excel"; // not sure in content type 
//Get the physical path to the file. 
string filePath = @"c:Test\data.xls"; 
//Write the file directly to the HTTP content output stream. 
Response.WriteFile(filePath); 
Response.End(); 

但它也依賴於客戶端設置。

1

使用

response.AddHeader("Content-Disposition", "inline; filename=" + FileName + ";"); 

無論是打開直接依賴於客戶端的安全設置,這可能工作,但沒有保證......

相關問題