I have never worked with Crystal Reports and plan to explore the product from a .Net development perspective. Below is a quote from Crystal Reports .Net Developer Documentation:
"You can host your report in either a Web or Windows application with one of the Crystal Reports viewer controls, or use the extensive API to interact with the report programmatically at runtime."
I plan to focus not on the creation of reports, but the consumption of existing reports defined within Crystal and attempt to expose and interact with them from a .Net Platform.
Create a simple report in Crystal Reports.
Expose the report with an interactive control from ASP.Net.
Stream a PDF version of the report from an ASP.Net using the Crystal API
Before we get started, my environment is:
Windows Vista (IIS 7)
Visual Studio 2005 Team Suite
SQL Server 2005
Crystal Reports XI R2
Create a simple report in Crystal Reports
We first need a report to work with. So let's create a very simple report.
Open Crystal Reports
Go to File->New->Standard Report
In the Standard Report Creation Wizard window, select Create New Connection->OLE DB (ADO)
In the OLE DB (ADO) window, select SQL Native Client provider.
Click Next
Server for this example is "." Which represents the my local Sql Server 2005 instance, you should fill out your specific server information and credentials.
Select the Adventure Works database.
Select Integrated Security if it applies.
Click Next
Select Current Connections->Adventure Works->Human Resources->Tables->Employee
Click the Right Arrow Button to add to Selected Tables
Click Next
Add some fields for the report
Click Next
Don't add anything for Grouping, just click Next
Don't add anything for Record Selection, just click Next
Let's add a little color, select Block (Blue)
Click Finish
You should now see the below screen
Go to File->Save
I saved the report to c:\reports\SampleReport.rpt, select your location and remember for later use.
Click Save
Make this report available on an ASP.Net site
Now that we have a sample report, we need to get it to the users of our ASP.Net web application.
Open Visual Studio 2005
Create a new ASP.Net Web Application
*I have decided to do this in C#, but of course either language will work.
In your Toolbox, you of you have Crystal Reports Developer Edition installed, you should see tools for Crystal Reports
Select the Design view for Default.asp
Drag and Drop the CrystalReportViewer to the design surface
Uncheck Enable Toolbar
Uncheck Enable Group Tree
In the Choose Report Source drop down, select new report source
Leave the name as CrystalReportSource1
For the CrystalReportSource select Browse
Navigate to the report we created earlier (c:\reports\SampleReport.rpt) and click Open
You should now see your report in the design surface.
Run the web site by clicking the green Start Debugging button.
And there is your report!
Note: This blog entry is not diving deep into the CrystalReportViewer control, this is just an example to get you started.
Stream a PDF version of the report from an ASP.Net site using the Crystal API
Now that we have successfully used the built-in control, let's try using the .Net API provided by Crystal Reports.
First let's add a new Web Form called PDFReport.aspx.
*Add a Reference to CrystalDecisions.CrystalReports.Engine
*Add a Reference to CrystalDecisions.CrystalReports.Shared
Add the code below to our code behind for PDFReport.aspx.cs
The ReportDocument is the key to working with the report.
Right Click on PDFReport.aspx and Set as Start Page
Run the web site by clicking the green Start Debugging button.
You should see your report embedded in the browser window!
If you want, you can set the third parameter on ExportToHttpResponse to make the report open as an attachment, which gives the user the ability to Open or Save the report.
*note that you may have two options. I am using .Net 2.0 so I will choose the one with "dotnet2" in the path.
Conclusion
After only a few hours of working with Crystal Reports, it is clear that it is a robust and enterprise solution for report development and delivery with good integration into a .Net development environment. This post is a simple Hello World and the world is huge!
Additional Comments
As doing this novice research, I noticed a lot of people complaining about a "Logon Failed Error" and I ran across a blog that describes how to fix it on Code Project, this may save someone a lot of research time.
http://www.codeproject.com/aspnet/crCode.asp