2014-09-23 155 views
0
protected void btn_download_Click(object sender, EventArgs e) 
{ 
    Response.Clear(); 
    Response.ContentType = "application/pdf"; 
    Response.AppendHeader("Content-Disposition", "attachment; filename=foo.pdf"); 
    string filePath = Server.MapPath(Request.ApplicationPath) + " \\Member\\Attachments" ; 
    Response.TransmitFile(filePath); 
    Response.End(); 
} 

我用上面的鏈接代碼下載網頁到PDF文件並保存在本地文件。但是由於對路徑的訪問被拒絕,我得到了錯誤。請幫助我。下載PDF文件的頁面並保存在C#本地文件夾中#

回答

1

在filePath變量中缺少本地文件名。追加文件名稱。並確保您的附件目錄有權訪問IIS用戶的文件。

string filePath = Server.MapPath(Request.ApplicationPath) + " \\Member\\Attachments\\foo.pdf" ; \\Append your file name here. 
+0

謝謝你..我知道這個foo.pdf是什麼嗎?在那個位置應該有一個名爲foo.pdf的文件名? – user3804364 2014-09-23 04:50:59

+0

是的。您在該物理位置出現的實際文件名稱。 foo.pdf只是例如 – 2014-09-23 04:55:05

+0

我試過了,但我得到了下載的foo.pdf文件。但我想要的是下載下載按鈕的頁面將作爲pdf下載。下載按鈕現在在數據列表中。我希望那些像證書一樣的datalist的內容可以下載爲pdf格式。 – user3804364 2014-09-23 05:04:03

相關問題