Opening PDF in new tab using ASP.NET

I am testing the code below, but it has no action when I click button to open a PDF in New Tab.

Ta missing something below?

Tests.aspx

Clique <asp:LinkButton OnClick="linkPDF_click" ID="linkPDF" runat="server">aqui</asp:LinkButton> para abrir seu PDF.

Tests.aspx.cs

protected void linkPDF_click(object sender, EventArgs e) 
{
  string FilePath = Server.MapPath("~/MediaFiles/Comuns/PDF/Arquivo Fatura.pdf");
  WebClient User = new WebClient();
  Byte[] FileBuffer = User.DownloadData(FilePath);
  if(FileBuffer != null)
  {
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", FileBuffer.Length.ToString());
    Response.BinaryWrite(FileBuffer);
  }
}
Author: Joao Torres Moreira, 2019-08-28

1 answers

Friend, I made one that did something similar that worked like this:

Vc would put in the case the direct code in the HTML, in the view that would have the link to click on the PDF

<strong>
   <a href="~/MediaFiles/Comuns/PDF/Arquivo Fatura.pdf" target="_blank">Visualizar PDF do manual</a>
</strong>

I tested here on my this working perfectly

 1
Author: DFernandes, 2019-08-28 21:14:10