Force browser to download PDF document instead of opening it

后端 未结 5 1599
太阳男子
太阳男子 2020-12-01 12:14

I want to make the browser download a PDF document from server instead of opening the file in browser itself. I am using C#.

Below is my sample code which I used. It

5条回答
  •  误落风尘
    2020-12-01 13:01

    In case if we are trying to write a bytes array then we can use below one.

                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AppendHeader("Content-Disposition", "attachment; filename=file.pdf");
                Response.BufferOutput = true;
                Response.AddHeader("Content-Length", docBytes.Length.ToString());
                Response.BinaryWrite(docBytes);
                Response.End();
    

提交回复
热议问题