【问题标题】:Download upload file from specific folder从特定文件夹下载上传文件
【发布时间】:2015-09-19 00:31:32
【问题描述】:

我想将文件夹内的上传文件下载到我的项目中.. 我的数据库表

我的上传代码是

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();   
        }

它会产生以下错误

"找不到文件 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...谢谢

【问题讨论】:

    标签: asp.net c#-4.0 visual-studio-2012 file-upload entity-framework-4


    【解决方案1】:

    试试这个

    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_MD.Golam_Shahriar.pdf'。'
    • 替换 Response.TransmitFile(filePath);到 Response.TransmitFile(Server.MapPath("~/PatientDocuments/") +filename);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多