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