Prompt user to download PDF file instead of opening

后端 未结 6 2116
庸人自扰
庸人自扰 2021-01-05 07:14

In my project site, if I click on a link, the PDF opens in a new or parent window. Well I want a box to appear that prompts the user to download the file instead of opening

6条回答
  •  感动是毒
    2021-01-05 07:45

    Since you've tagged it .NET, I'd say this is your best solution:

    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment;filename=download.pdf");
    Response.WriteFile(Server.MapPath("~/files/myFile.pdf"));
    Response.Flush();
    Response.Close();
    

提交回复
热议问题