从特定文件夹下载上传文件
Download upload file from specific folder
我想将文件夹中的上传文件下载到我的项目中..
我的数据库 Table
我的上传代码是
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 下载它时,它找不到它的目的地 Path。
这是上传代码
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();
}
它产生以下错误
"Could not find file E:\CoreZ
IT\June\Hospital-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();
我想将文件夹中的上传文件下载到我的项目中..
我的数据库 Table
我的上传代码是
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 下载它时,它找不到它的目的地 Path。 这是上传代码
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();
}
它产生以下错误
"Could not find file E:\CoreZ IT\June\Hospital-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();