2016-12-06 64 views
0

有我的問題。我試圖從asp.net項目目錄下載文件。文件在「日期」目錄中。我使用GridView完成了WebForm1.aspx頁面,該頁面顯示Date目錄中的文件。所有文件都顯示爲鏈接。
有我的代碼底部。無法從項目目錄(asp.net)下載文件

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if(e.CommandName == "Download") 
    { 
     Response.Clear(); 
     Response.ContentType = "text/plain"; 
     Response.AppendHeader("content-disposition", "filename" + e.CommandArgument); 
     Response.TransmitFile(Server.MapPath("~/Data/") + e.CommandArgument);    
     Response.End(); 
    } 
} 

我通過文件鏈接。之後,我的瀏覽器提供下載不是我的文件,但所有頁面的文件(WebForm1.aspx) 幫我解決這個問題。我做了什麼不正確?

image with problem

回答

1

你的性格頭是靠不住的(無attachment,缺少=),更改爲:

Response.AppendHeader("content-disposition", "attachment; filename=" + e.CommandArgument); 
+0

非常感謝。它解決了這個問題。 – Vand