Damiano
Damiano

Reputation: 11

Open .pdf file in new browser Tab ASP.NET

I have this function named StampaSingola:

Private Sub StampaSingola()
        Dim rpt As New rptLettera
        CType(rpt.DataSource, SqlDBDataSource).SQL = "Select * from vwLettere WHERE IdLettera IN (" & Request.QueryString("IdLettera") & ")"

    rpt.Run(False)

    If Not rpt Is Nothing Then
        Dim exp As New PdfExport
        ' Create a new memory stream that will hold the pdf output
        Dim memStream As New System.IO.MemoryStream
        ' Export the report to PDF:
        exp.Export(rpt.Document, memStream)
        exp.Dispose()
        exp = Nothing

        With Me.Context.Response
            .Buffer = True
            .ContentType = "application/pdf"
            .AddHeader("content-disposition", "attachment; filename=Archilet_Lettera_" & Request.QueryString("IdLettera") & ".pdf;")
            .BinaryWrite(memStream.ToArray)
            .Flush()
            .End()
        End With

        rpt.Document.Dispose()
        rpt.Dispose()
        rpt = Nothing
    End If
End Sub

How do I make open the pdf in a new browser tab? Thank you

Upvotes: 1

Views: 386

Answers (1)

Ayman Barhoum
Ayman Barhoum

Reputation: 1255

  • Create new page for downloading "download.aspx"
  • Move your code to page_load event in "download.aspx" page.
  • on button_click event of your first page put the following code :

protected void btnDownload_Click(object sender, EventArgs e) { Response.Write(string.Format("window.open('{0}','_blank');", "download.aspx")); }

Upvotes: 1

Related Questions