Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Introduction

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();

crReportDocument.Load("path_to_your_report_file.rpt");
//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;

crReportDocument.Export();

crReportDocument.Export();

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.

License

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

Share

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

Comments and Discussions

 
GeneralMy vote of 3 Pinmemberyoh.asakura29-Apr-11 1:41 
GeneralOpening a crystal report in PDF format with a button click Pinmemberarunkhd1232-Nov-08 0:38 
GeneralAppending PDF File Pinmemberidreesbadshah18-Nov-07 19:58 
Questionwindows services Pinmemberblues9130-May-07 1:03 
GeneralDisplay field name for each record in crystal record PinmemberNisha_D17-Mar-07 20:19 
Questionhow to make crystal report in asp.net ? PinmemberAmit sukhadiya15-Mar-07 0:58 
AnswerRe: how to make crystal report in asp.net ? PinmemberFarhan Ali15-Mar-07 19:34 
Questionhow i can make report in C#.net? PinmemberMember #319860215-Mar-07 0:29 
AnswerRe: how i can make report in C#.net? PinmemberFarhan Ali15-Mar-07 19:43 
General.Net v1.1.4322 PinmemberStevenHenning2-Jan-07 3:50 
Generalmmmm... PinmemberNirosh28-Nov-06 22:07 
GeneralRe: mmmm... PinmemberNirosh5-Dec-06 21:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.8.140905.1 | Last Updated 28 Nov 2006
Article Copyright 2006 by Farhan Ali
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid