You can export a Crystal Report to various formats using CrystalReportViewer's Export option. However, there are occasions when you want your users to see the report direct in PDF format in the browser as soon they click the Report button in your application.
The ReportDocument class provides Export methods to export a report to various formats including PDF, Excel, Word, and HTML.
The following steps will guide you to achieve the same:
- Add crystal report (.cr) file to your ASP.NET application.
- Add a report instance on the page level.
Dim report As MyReport = New MyReport
- Populate reports data on Page_Init
' Get data in a DataSet or DataTable
Dim ds As DataSet = GetData()
' Fill report with the data
report.SetDataSource(ds)
- Export Report
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "ExportedReport")
If you wish to format report to other formats, just change the ExportFormatType enumeration value to your desired format.
If you wish to download the report, then you simply change the third parameter of ExportToHttpResponse method in Step 4 to True.
The following code shows how to export a report to other formats including Word and Excel.
' Export report to the selected format
If ExportFormatList.SelectedItem.Text = "Adobe (PDF)" Then
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
ElseIf ExportFormatList.SelectedItem.Text = "MS Word" Then
report.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, True, "ExportedReport")
ElseIf ExportFormatList.SelectedItem.Text = "MS Excel 97 - 2000" Then
report.ExportToHttpResponse(ExportFormatType.Excel, Response, True, "ExportedReport")
ElseIf ExportFormatList.SelectedItem.Text = "MS Excel 97 - 2000 (Data Only)" Then
report.ExportToHttpResponse(ExportFormatType.ExcelRecord, Response, True, "ExportedReport")
End If

sachin jagtapPosted Aug 29, 2012, 7:19 AM
Thank u very much for help
sachin jagtapPosted Aug 29, 2012, 7:19 AM
Thank u very much for help
LeePosted Sep 14, 2010, 2:25 PM
Hi, I have a crystal report which includes 4 subreports. When I preview the report, it works fine. But when i export it into a pdf file, it has some mistake. The report in pdf file has a section repeats in many times. Anyone can help me? Thanks in advance
Narsingrao ChavanPosted Jun 4, 2010, 1:30 AM
Hi Mahesh, This article is really helpfull. But I am stuck with passing one of the parameters, that is Response. So could you please explain what is the Response parameter in the above ExportToHttpResponse() method call? Regards, Narsing
reshma pundePosted May 6, 2010, 8:07 AM
how one can save crystalreport automatically in pdf format
smithaPosted Dec 11, 2008, 5:44 AM
Hi Mahesh, I read the about article and it works fine if the user wants to export the Report directly with out the help of Crystal Report viewer.But what should be done if the report has to get exported/Printed via Crystal Reoport Viewer ?I have the icons dispalyed for print and export on Crystal Reoport Viewer .But the page is getting refreshed when i click on any of the icons.What should i do to have the respective functionality for each icon? Regards, smitha
prachi joglekarPosted Nov 14, 2008, 1:50 AM
Report Name D:\PrachiJoglekar\PRACHI\OnlinePaymentSystem\USERWISE.rptLoaded Report Loaded Report could not create report pdf CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: Missing parameter values. ---> System.Runtime.InteropServices.COMException (0x8004100E): Missing parameter values. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) --- End of inner exception stack trace --- at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export() at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export() at USERWISE.CreateReport(String sReport, String sReportFormula)
Sudarshana RajeshPosted Mar 17, 2008, 1:31 AM
works fine for me. thanks also i need a pdf report in new page and not in the same page. if asattachments is given as true, i get a box which asks for Open/Save/Cancel. and opens in a new page i dosent need any questions. if i give print, i just need to get printed as PDF in a new page. Anyone pls help me Thanks in advance.
Santhosh balanPosted Jan 5, 2008, 8:07 AM
Hi Mahesh I tried creating the report as you said.But i get an System.Threading.ThreadAbortException with the message "Unable to evaluate expression because the code is optimized or there is a native frame on top of the call stack" at the report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "ExportedReport") line due to which i get a blank browser window without the report.Please guide me. Regards Santhosh
AurPosted Dec 7, 2007, 11:39 AM
did everything that was in your article, but I am getting a Database Logon error. The error was: CrystalDecisions.CrystalReports.Engine.LogOnException: Database logon failed. ---> System.Runtime.InteropServices.COMException (0x8004100F): Database logon failed. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) --- End of inner exception stack trace --- at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.ReportDocument.y(ExportOptions R) at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportOptions options, HttpResponse response, Boolean asAttachment, String attachmentName) at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportFormatType formatType, HttpResponse response, Boolean asAttachment, String attachmentName) at CIMS.crpt_equipmentTypeNumIssues.btn_export_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\cims2\Star\report\crpt\crpt_equipmentTypeNumIssues.aspx.vb:line 380 I am using Crystal Report XI and PUSH method. I don’t understand why it will ask for Database credentails as I am using the PUSH model. I hope you can help me. Thank you in advance.
kalpana kadamPosted Feb 23, 2007, 9:44 AM
HELLO, I M KALPANA I M FACING PROBLEM WHILE EXPORTING CRYSTAL REPORT TO PDF WITH PARAMETERS. IT IS GIVING ME CORRECT OUTPUT IN CRYSTALREPORTVIEWER BUT I M NOT GETTING ANY DATA INTO PDF FILE.IT IS JUST SHOWING TITLE AND BOX IN PDF BUT NOT DATA.IF I PASS ONE PARAMETER IT IS SHOWING REPORT IN PDF WITH CORRECT DATA BUT NOT FOR MORE THAN ONE PARAMETERS. WILL U PLZ HELP ME IN THIS MATTER. CODE I M USING IS ReportDocument crReportDocument= new ReportDocument(); crReportDocument.Load(Server.MapPath("cryForAllLockerTypes.rpt")); crReportDocument=con.GetConnection(crReportDocument); ParameterDiscreteValue crtParamDiscreteValue; ParameterField crtParamField; ParameterFields crtParamFields; crtParamDiscreteValue = new ParameterDiscreteValue(); crtParamField = new ParameterField(); crtParamFields = new ParameterFields(); crtParamDiscreteValue.Value = "028"; crtParamField.ParameterFieldName = "sol"; crtParamField.CurrentValues.Add(crtParamDiscreteValue); crtParamFields.Add(crtParamField); crtParamDiscreteValue = new ParameterDiscreteValue(); crtParamField= new ParameterField(); crtParamDiscreteValue.Value = "00"; crtParamField.ParameterFieldName = "extn"; crtParamField.CurrentValues.Add(crtParamDiscreteValue); crtParamFields.Add(crtParamField); crtParamDiscreteValue = new ParameterDiscreteValue(); crtParamField= new ParameterField(); crtParamDiscreteValue.Value = txtCabFrom.Text; crtParamField.ParameterFieldName = "cabfrom"; crtParamField.CurrentValues.Add(crtParamDiscreteValue); crtParamFields.Add(crtParamField); crtParamDiscreteValue = new ParameterDiscreteValue(); crtParamField= new ParameterField(); crtParamDiscreteValue.Value = txtCabTo.Text; crtParamField.ParameterFieldName = "cabto"; crtParamField.CurrentValues.Add(crtParamDiscreteValue); crtParamFields.Add(crtParamField); crReportDocument.SetParameterValue("extn",crtParamDiscreteValue); crReportDocument.SetParameterValue("sol",crtParamDiscreteValue); crReportDocument.SetParameterValue("cabfrom",crtParamDiscreteValue); crReportDocument.SetParameterValue("cabto",crtParamDiscreteValue); CrystalReportViewer1.ParameterFieldInfo = crtParamFields; CrystalReportViewer1.ReportSource=crReportDocument; CrystalReportViewer1.DataBind(); crReportDocument.ExportOptions.ExportFormatType =ExportFormatType.PortableDocFormat; crReportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions(); diskOpts.DiskFileName ="C:\\Report44.pdf"; //"c:\\try.pdf"; crReportDocument.ExportOptions.DestinationOptions = diskOpts; crReportDocument.Export(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; string filename1 = "attachment;filename="+"Report44.pdf"; Response.AddHeader("Content-Disposition", filename1); Response.WriteFile("C:\\Report44.pdf"); Response.Flush(); Response.Close(); System.IO.File.Delete("C:\\Report44.pdf"); CLIENT SIDE CODE.FILE MUST BE CREATED ON CLIENT MACHINE.