Using Crystal Report Viewer

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 to enter the path to the XML feed. (ex: XMLOrdersManifest.xml)

Both files are stored in the root of the application.

RprPre1.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:

RprPre2.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
DataSet dtsData=new DataSet();
ReportDocument oRpt=
new ReportDocument();
//try to load the specified report file
oRpt.Load(this.txtReportPath.Text, OpenReportMethod.OpenReportByTempCopy);
//try to load data for the report
dtsData.ReadXml(this.txtXMLPath.Text);
string missingInSource, missingInReport;
//checks that fields in XML file match to the fields specified in the report file
bool fieldsMissing = !CheckMissingFields(oRpt,dtsData,out missingInSource, out missingInReport);
//informs about the result of checking
ShowMissingFields(missingInSource,missingInReport);
if (!fieldsMissing)
{
oRpt.SetDataSource(dtsData);
cRVOrder.ReportSource=oRpt;


Similar Articles