RptPreview 1.1 using Crystal Reports Viewer in VB.NET

Purpose

The following small application is designed to allow testing created reports with XML feeds used as data sources. The program checks that fields in report match to the fields in XML and then shows the report with loaded data in the report viewer.

How to Use?

1. Fill the following fields "Path to Report" and "Path to XML file": The "Path to Report textbox" serves for entering the path to a report. (Ex: CROrdersManifest.rpt).

The "Path to XML file" allows entering the path to the XML feed. (ex: XMLOrdersManifest.xml). 

Both files are stored in the root of the application.

Browse-buttons-open.jpg

Note: Browse buttons open a standard File Open dialog.

2. Click Preview Report

Note: The program checks that specified report and XML match to each other- i.e. they contain the same fields. If the program finds inconsistence it reports about it as it is shown below:
 

Click-Preview-Report.jpg

Advice

In order to get XML file use WriteXml method of dataset class. Like the following:

OrderDataSet.WriteXml("C:\Inetpub\wwwroot\UniversalTicketSystem\Docs\USPS.xml").

Having created XML file you can allow designers to create reports without permanent access to your database.

Implementation details

'initializing
Dim dtsData As New DataSet
Dim oRpt As New ReportDocument
'try to load the specified report file
oRpt.Load(Me.txtReportPath.Text, OpenReportMethod.OpenReportByTempCopy)
'try to load data for the report
dtsData.ReadXml(Me.txtXMLPath.Text)
Dim missingInSource, missingInReport As String
'checks that fields in XML file match to the fields specified in the report file
Dim fieldsMissing As Boolean = Not CheckMissingFields(oRpt, dtsData, missingInSource, missingInReport)
'informs about the result of checking
ShowMissingFields(missingInSource, missingInReport)
If Not fieldsMissing Then
oRpt.SetDataSource(dtsData)
cRVOrder.ReportSource = oRpt
End If


Similar Articles