View Single Post
  #2 (permalink)  
Old October 26th, 2014, 12:10 AM
hrothenb hrothenb is offline
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Smile how to view crystal report in asp.net vb

Try:

Code:
 
Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
    End Sub

    Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click

        OpenPDF(Request.ApplicationPath + "/Reports/Report.pdf")

    End Sub


    Private Sub OpenPDF(downloadAsFilename As String)
        Dim RptDoc As New ReportDocument()
        RptDoc.Load(Server.MapPath(Request.ApplicationPath + "/Reports/myreport.rpt"))
        RptDoc.SetDatabaseLogon("user", "password", "server", "database")

        Dim stream As New BinaryReader(RptDoc.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat))
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & downloadAsFilename)
        Response.AddHeader("content-length", stream.BaseStream.Length.ToString())
        Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
        Response.Flush()
        Response.Close()
    End Sub
End Class
Reply With Quote