Asp.net 从特定文件夹下载上载文件
我想将文件夹中的上载文件下载到我的项目中。。 我的数据库表 我的上传代码是Asp.net 从特定文件夹下载上载文件,asp.net,c#-4.0,visual-studio-2012,file-upload,entity-framework-4,Asp.net,C# 4.0,Visual Studio 2012,File Upload,Entity Framework 4,我想将文件夹中的上载文件下载到我的项目中。。 我的数据库表 我的上传代码是 string filename = Path.GetFileName(FileUploadPatDoc.FileName); string pathName = Path.GetFullPath(FileUploadPatDoc.PostedFile.FileName); FileUploadPatDoc.SaveAs(Server.MapPath("~/PatientDocuments/") +filename);
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\June\Hospital\22-06\Final\CZ_BHC\CZ_BHC\BHC\CV_MD.Golam_Shahriar.pdf“
但是我需要从E:..\PatientDocuments\CV_MD.Golam_Shahriar.pdf
请帮助我,我正在使用VS 2012。。。谢谢试试这个
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + "");
Response.TransmitFile(filePath);
Response.End();
实现给定代码后,它会给我以下错误“找不到文件”C:\Program Files(x86)\IIS Express\CV\u MD.Golam\u Shahriar.pdf“。替换响应.TransmitFile(文件路径);到Response.TransmitFile(Server.MapPath(“~/PatientDocuments/”)+文件名);