Click here to Skip to main content
12,075,066 members (65,352 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked

Exporting Crystal Reports in ASP.NET

, 28 Nov 2006
Rate this:
Please Sign up or sign in to vote.
This demo will help the developers to export Crystal Reports in ASP.NET


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.

The Process

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.

Step 1

Add three assemblies:

  1. CrystalDecisions.CrystalReports.Engine.dll
  2. CrystalDecisions.ReportSource.dll
  3. CrystalDecisions.Shared.dll

Step 2

Now in the code, add them like this:

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;

Step 3

You can add this code under the PageLoad() Function or under the Button Click() Event.

//Give name of the report which you have created
string exportFileName = "CrystalReport1.rpt";
string exportPath = "C:\\crystalreport1.pdf"; //where file will be exported
ReportDocument crReportDocument = new ReportDocument();

//Export the report to disk.

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

ExportOptions crExportOptions;

DiskFileDestinationOptions crDestOptions = new DiskFileDestinationOptions();

crDestOptions.DiskFileName = exportPath;

crExportOptions = crReportDocument.ExportOptions;

crExportOptions.DestinationOptions = crDestOptions;
//Specify export destination type
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
//Specify the format in which you want to export (like .doc,.pdf etc)
crExportOptions.ExportFormatType = ExportFormatType.CrystalReport;



Method 2 - Using the 'ExportToDisk' Method

crReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, exportPath);

Once the code is executed successfully, you will find the exported report in PDF format in the C drive as specified by the 'exportPath' variable.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Farhan Ali
Web Developer
Pakistan Pakistan
I am Farhan Ali from Pakistan.I have done BS(CS)Hons from University of Arid Agriculture Rawalpindi in July 2006.My experties or field of interest is C#.NET and ASP.NET.
I am also working on new technologies like AJAX etc

You may also be interested in...

Comments and Discussions

GeneralOpening a crystal report in PDF format with a button click Pin
arunkhd1232-Nov-08 1:38
memberarunkhd1232-Nov-08 1:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 28 Nov 2006
Article Copyright 2006 by Farhan Ali
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid