Introduction
When we develop a report for web application, the RPT file usually embedded into an DLL file. So when we want to edit the report, we must recompile the project. This is the simple solution for reading RPT file then displays it as PDF.
<o:p>
Now let’s creating a function to export and display your report into PDF.
<o:p>
Private Function PrintDocument(ByVal SourceReport As Object, ByVal FormatType As CrystalDecisions.Shared.ExportFormatType, ByVal PaperSize As CrystalDecisions.Shared.PaperSize, ByVal PaperOrientation As CrystalDecisions.Shared.PaperOrientation)<o:p>
'Copyright IMAWA 2005 (Bluechip_Asia@yahoo.com)<o:p>
'For Educational Purpose Only<o:p>
'For Explanation of this function, see my previous article<o:p>
With SourceReport.FormatEngine.PrintOptions<o:p>
.PaperSize = PaperSize<o:p>
.PaperOrientation = PaperOrientation<o:p>
End With<o:p>
Dim st As System.IO.Stream<o:p>
Dim b() As Byte<o:p>
st = SourceReport.ExportToStream(FormatType)<o:p>
Page.Response.ClearHeaders()<o:p>
Page.Response.ContentType = "application/pdf"<o:p>
ReDim b(st.Length)<o:p>
st.Read(b, 0, CInt(st.Length))<o:p>
Page.Response.BinaryWrite(b)<o:p>
Page.Response.End()<o:p>
End Function
<o:p>
Next, we call the function when page loaded.
<o:p>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Copyright IMAWA 2005 (Bluechip_Asia@yahoo.com)<o:p>
'For Educational Purpose Only<o:p>
'For Explanation of this function, see my previous article<o:p>
Dim myRpt As New ReportDocument<o:p>
myRpt.Site = Me.Site<o:p>
Try<o:p>
myRpt.Load(MapPath("../RPTFiles/Training.Rpt"))<o:p>
PrintDocument(myRpt, CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat, CrystalDecisions.[Shared].PaperSize.PaperLetter, CrystalDecisions.[Shared].PaperOrientation.Portrait)<o:p>
Catch ex As Exception<o:p>
Exit Sub<o:p>
End Try<o:p>
End Sub<o:p>
<o:p>
<o:p>
The Complete Source code are :<o:p>
<o:p>
Imports CrystalDecisions.CrystalReports.Engine<o:p>
Imports CrystalDecisions.ReportSource<o:p>
Imports CrystalDecisions.Shared<o:p>
<o:p>
Public Class ReportTraining<o:p>
Inherits System.Web.UI.Page<o:p>
<o:p>
#Region " Web Form Designer Generated Code "<o:p>
<o:p>
'This call is required by the Web Form Designer.<o:p>
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<o:p>
<o:p>
End Sub<o:p>
<o:p>
'NOTE: The following placeholder declaration is required by the Web Form Designer.<o:p>
'Do not delete or move it.<o:p>
Private designerPlaceholderDeclaration As System.Object<o:p>
<o:p>
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<o:p>
'CODEGEN: This method call is required by the Web Form Designer<o:p>
'Do not modify it using the code editor.<o:p>
InitializeComponent()<o:p>
End Sub<o:p>
<o:p>
#End Region<o:p>
<o:p>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<o:p>
'Put user code to initialize the page here<o:p>
Dim myRpt As New ReportDocument<o:p>
myRpt.Site = Me.Site<o:p>
Try<o:p>
myRpt.Load(Me.MapPath("../CPXPrint/Training.Rpt"))<o:p>
PrintDocument(myRpt, CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat, CrystalDecisions.[Shared].PaperSize.PaperLetter, CrystalDecisions.[Shared].PaperOrientation.Portrait)<o:p>
Catch ex As Exception<o:p>
Exit Sub<o:p>
End Try<o:p>
End Sub<o:p>
<o:p>
Private Function PrintDocument(ByVal SourceReport As Object, ByVal FormatType As CrystalDecisions.Shared.ExportFormatType, ByVal PaperSize As CrystalDecisions.Shared.PaperSize, ByVal PaperOrientation As CrystalDecisions.Shared.PaperOrientation)<o:p>
'Copyright IMAWA 2005 (Bluechip_Asia@yahoo.com)<o:p>
'For Educational Purpose Only<o:p>
'For Explanation of this function, see my previous article<o:p>
With SourceReport.FormatEngine.PrintOptions<o:p>
.PaperSize = PaperSize<o:p>
.PaperOrientation = PaperOrientation<o:p>
End With<o:p>
Dim st As System.IO.Stream<o:p>
Dim b() As Byte<o:p>
st = SourceReport.ExportToStream(FormatType)<o:p>
Page.Response.ClearHeaders()<o:p>
Page.Response.ContentType = "application/pdf"<o:p>
ReDim b(st.Length)<o:p>
st.Read(b, 0, CInt(st.Length))<o:p>
Page.Response.BinaryWrite(b)<o:p>
Page.Response.End()<o:p>
End Function<o:p>
End Class
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.