How to download file with asp.net on buttton's onClick event?

前端 未结 5 1862
时光取名叫无心
时光取名叫无心 2021-02-06 15:37

I have a String variable (in C#) that contain the full path of PDF file on my server (like that \"~/doc/help.pdf\").

I want that in click on button, this file will down

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 16:14

    Response.ContentType = "Application/pdf";
    
    Response.AppendHeader("Content-Disposition", "attachment; filename=File_Name.pdf");
    
    Response.TransmitFile(Server.MapPath("Folder_Name/File_Name.pdf"));
    
    Response.End();
    

提交回复
热议问题