在新浏览器Tab ASP.NET中打开.pdf文件

时间:2016-01-27 09:24:03

标签: asp.net tabs

我有这个名为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

如何在新的浏览器标签中打开pdf? 谢谢

1 个答案:

答案 0 :(得分:1)

  • 创建新页面以供下载" download.aspx"
  • 将代码移至" download.aspx"中的page_load事件页。
  • 在第一页的button_click事件中输入以下代码:

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