It is relatively easy to retrieve data from a database and display it using any of the bound controls. This is especially so in ASP.NET 2.0 where the amount of code you need to write has been drastically reduced. However, to present the data in a formal, board-room friendly format and distribute it in hard copy, or for look-up, or both is challenging. Crystal Reports do this remarkably well. Microsoft has been bundling Crystal reports ever since the VB days, and it ships with every version of VS 2005. It is well integrated with Visual Studio 2005 as we shall see shortly. For highly functional and aesthetically pleasing report generation, Crystal Report is ideally suited. It is very versatile and can use data from a variety of databases as well as non-traditional sources.
I have gone through a number of websites and search engines but did not find any example which can help the developers to Export Crystal Reports in ASP.NET or C#.NET in an easy way. I am sure this article will help you in a better way
For Exporting Crystal Reports, the following steps must be followed.
Add three assemblies:
Now in the code, add them like this:
You can add this code under the
PageLoad() Function or under the Button
string exportFileName = "CrystalReport1.rpt";
string exportPath = "C:\\crystalreport1.pdf"; ReportDocument crReportDocument = new ReportDocument();
There are two methods to export a report to disk. The first is to use the '
ExportOptions' class to define the exporting options while the second is to use the '
ReportDocument.ExportToDisk' shortcut method. Both are described below.
Method 1 - Using the 'ExportOptions' Class
DiskFileDestinationOptions crDestOptions = new DiskFileDestinationOptions();
crDestOptions.DiskFileName = exportPath;
crExportOptions = crReportDocument.ExportOptions;
crExportOptions.DestinationOptions = crDestOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.CrystalReport;
Method 2 - Using the 'ExportToDisk' Method
Once the code is executed successfully, you will find the exported report in PDF format in the C drive as specified by the '