2011-04-14 56 views
1

以及我需要有一個下載按鈕...我要去的地方的文件是例如如何在c#asp.net中製作下載按鈕?用查詢?

從表中選擇網址其中id = 3;

?(這是要返回「C:/我的文檔/圖片/ file.xxx);

現在我有一個按鈕來下載它 怎樣下載該文件比如果在該網址發現?

回答

3

採取什麼你正在嘗試做的是創造一個下拉列表,旁邊有一個按鈕。您可以根據您的查詢填充下拉..點擊按鈕你可以發送文件作爲流來響應。

Response.ContentType = "image/jpeg"; 
Response.AppendHeader("Content-Disposition","attachment; filename=downloadedFile.JPG"); 
Response.TransmitFile(@"c:/my documents/images/file.xxx"); 
Response.End(); 
2
Response.ContentType = "image/jpeg"; // set content type of file by using it's extension 
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg"); // make the save as dialog appear with a friendly file name 
Response.TransmitFile("c:/my documents/images/file.xxx"); // do the hard stuff! 
Response.End(); 

Rick Strahl's Weblog

1
Response.Clear(); 
Response.ContentType = "application/x-doc"; 
Response.AppendHeader("Content-Disposition","attachment; filename=file.doc"); 
Response.TransmitFile("c:/my documents/docs/file.doc"); 
Response.End(); 
相關問題