Products
Database Search Solution (New Version) Search Control SEO Pager Highlighter Shortcut Controls Crypt Package Free ASP.NET Controls
Geotargeting Component ASP.NET Media Player Control Flash Video Player Control Services
ASP.NET Telecommute Jobs Free IP Location Lookup Test .Net Regular Expressions CSS/Table/DIV Page Layouts Custom Programming Article Sites Master List |
Export Crystal Reports to PDF fileReports are used by business for various management purposes. Crystal reports is very versatile and easy to use reporting tool that is bundled with the Microsoft Visual Studio .Net. There have been many enhancements in the latest version of crystal reports which make it simpler for developers to export reports directly to the HTTP response object. The export option is very useful when business users want to have reports exported different formats such as PDF, Excel, Word and HTML. They want this facility in order to download the report and store it for future use or to modify the report further (possible in case of Word and Excel). In many cases the export option is used for scheduled reports to be send via email, In this case, the exporting is done on the server side and the exported file is attached to an email and send to the user's email id. In this tutorial, I will be showing you how to export a report to PDF format, but it can be easily modified to export the report in other formats. Create a Crystal Report and display to the userCreate a New ASP.NET Web Site ProjectI will be using an XML file as the data source for this tutorial. In normal scenarios a business layer class would return a dataset or datatable containing data to be displayed in the report. So I created an XML file with customer data and will be reading the contents into a Dataset. Add XML file to the ProjectRight-Click on App_Data folder and select Add Existing Item Browse to the XML file and select it: Add a crystal report to the projectRight-Click on the website root and select Add New Item. Select "Crystal Report". Enter the name of the report, I used the default name given by the IDE. When the Crystal report wizard comes up select "Standard" and click OK. Select a data source for the report. Expand the Create New Connection node and then expand the ADO.net option. Browse to the XML file and select the file. The Customers table will appear in the list of data sources, add the table to selected table list by clicking on the right arrow. Select all the columns that you need to display in the reports. I selected all of them for simplicity. Setup grouping as needed to display the report. Setup fields available for filtering. Select the layout of report that you want. The report is now created, you can now change the layout, add logos, etc. Display the report on a web pageIn the design view drag and drop the crystal reports viewer from Toolbox onto the web page. Add a button which will handle the displaying of the report. The HTML for body of the webpage should like as follows: <body> Remember to add following namespaces at the top of code behind page for referencing Crystal Report objects. using
CrystalDecisions.CrystalReports.Engine; The event handler should looks as follows: protected
void btnShow_Click(object
sender, EventArgs e) Run the Project to see if if works. Export the Crystal Report in PDF formatAdd a button to the web page so that user can click and get the PDF. The HTML for web page should looks as follows: <body> The Code behind for export is as follows: protected
void btnExport_Click(object
sender, EventArgs e) Export to other formatsThe report can be exported in different formats as follow:
Run the project to see does it working. Once you click on the Export the PDF button the dialog box to download the pdf file will appear. Now open the file and see if it is displayed properly. By the end if this tutorial you should be able to
You can download Sample Export Crystal Report To PDF Visual Studio Project, used in this tutorial. Many people found that Crystal Reports are complicate to learn. If you use SQL Server, nice solution is ApexSQL Report. Tutorial toolbar: Tell A Friend | Add to favorites | Feedback | |