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

前端 未结 5 1857
时光取名叫无心
时光取名叫无心 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:26

    I think you are looking for something like this.

    private void Button1_click(object sender, System.EventArgs e)
    {
        Response.ContentType = "Application/pdf";
        Response.AppendHeader("Content-Disposition", "attachment; filename=help.pdf");
        Response.TransmitFile(Server.MapPath("~/doc/help.pdf"));
        Response.End();
    }
    

提交回复
热议问题