Prompt user to download PDF file instead of opening

后端 未结 6 2069
庸人自扰
庸人自扰 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:39

    Change the Content-Type to application/octet-stream. You may find however, that some browsers will infer from the file extension that it should open as a PDF with your favorite PDF viewer.

    Response.ContentType = "application/octet-stream";
    

    Also, set the following:

    Response.AppendHeader( "content-disposition", "attachment; filename=" + name );
    

提交回复
热议问题