1

我想下載上傳文件是一個文件夾內到我的項目.. 我的數據庫表 下載上傳文件

我上傳的代碼是

string filename = Path.GetFileName(FileUploadPatDoc.FileName); 
string pathName = Path.GetFullPath(FileUploadPatDoc.PostedFile.FileName); 
FileUploadPatDoc.SaveAs(Server.MapPath("~/PatientDocuments/") +filename); 
fsDocuments.FileName = filename; // fsDocument is Table Object name 
fsDocuments.FilePath = pathName; 

它可以很好地和將文檔存儲在我的項目中的「PatientDocuments」文件夾中。 現在,當我想使用圖像按鈕從Gridview下載時,它無法找到它的目的地路徑。 這裏是上傳代碼

ImageButton Btn = (ImageButton)sender; 
GridViewRow row = (GridViewRow)Btn.NamingContainer; 
string fileName, filePath; 
Label file = (Label)grdPatientDocument.Rows[row.RowIndex].FindControl("lblFileName"); 
Label path = (Label)grdPatientDocument.Rows[row.RowIndex].FindControl("lblFilePath"); 

     if (file != null) 
     { 
      fileName = file.Text; 
      filePath = path.Text; 
      Response.ContentType = filePath; 
      Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); 
      Response.TransmitFile(Server.MapPath(fileName)); 
      Response.End(); 
     } 

它產生以下錯誤

「找不到文件E:\ COREZ IT \月\醫院\ 22-06 \決賽\ CZ_BHC \ CZ_BHC \ BHC \ CV_MD.Golam_Shahriar.pdf'」

但我需要從E:....\PatientDocuments\CV_MD.Golam_Shahriar.pdf

找到這個文件,請幫助我,我使用VS 2012 ...謝謝

回答

1

試試這個

Response.Clear(); 
Response.ContentType = "application/pdf"; 
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ""); 
Response.TransmitFile(filePath); 
Response.End(); 
+0

實施後您定的代碼它給我下面的錯誤 '找不到文件' C:\ Program Files文件(x86)的\ IIS快遞\ CV_MD.Golam_Shahriar.pdf '' – mgsdew

+1

替換Response.TransmitFile(filePath);到Response.TransmitFile(Server.MapPath(「〜/ PatientDocuments /」)+ filename); –

+0

謝謝,兄弟。 它現在的作品:) – mgsdew