I created a Crystal Report and connected it to an XML file at C:\SomeDir\Data.xml
.
At runtime, I may need to put the data in C:\SomeOtherDir\Data.xml
.
The code I have so far looks like this:
ReportDocument report = new ReportDocument();
report.Load("Report.rpt");
PrinterSettings printerSettings = new PrinterSettings();
PageSettings pageSettings = printerSettings.DefaultPageSettings;
report.PrintToPrinter(printerSettings, pageSettings, false);
That will print the report with the data at C:\SomeDir\Data.xml
. I want it to print the data at C:\SomeOtherDir\Data.xml
.
How can I do this?
ReportDocument report = new ReportDocument();
report.Load("Report.rpt");
DataSet reportData = new DataSet();
reportData.ReadXml(@"C:\SomeOtherDir\Data.xml");
report.SetDataSource(reportData);
PrinterSettings printerSettings = new PrinterSettings();
PageSettings pageSettings = printerSettings.DefaultPageSettings;
report.PrintToPrinter(printerSettings, pageSettings, false);
If the schema of the XML changes, you will need to open the report in the CR editor and "verify database" to update the schema it is bound to, or it will throw the mysterious "Logon Failed" error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With