Mithun Pradhan

Mithun Pradhan

  • 2.1k
  • 73
  • 3.3k

How to open pdf in new tab if pdf is there otherwise not?

May 23 2022 5:48 AM

<asp:Button ID="ButtonDownload" runat="server" OnClick="ButtonDownload_Click" class="c-btn c-btn--mini c-btn--primary" Text="Download" ></asp:Button>

 

protected void ButtonDownload_Click(object sender, EventArgs e)
        {
            ShowErrorAlertMessage(false);

            var webApiService = new WebApiService(TestUrl);
            
            var outputRootFolder = Server.MapPath("~/App_Data/");
            webApiService.GenerateReportFromApi(LabelTest.Text);
            
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", $"filename={fileName}");
            Response.TransmitFile(filePath);
            Response.End();

           
        }


Answers (1)