cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting Reports

paul_aziz
Explorer
0 Kudos

Hi everybody.

I tried exporting a crystal report version 13 report to PDF through Export button on CrystalReportViewer control toolbar. But I it threw exception (No reference set for the object)

My questions are:

  1. is it possibble to export a report to other format, e.g PDF by clicking the export button on the CrystalReportViewer control toolbar without any custom code?
  2. if it is possible, how?
  3. if it is not possible, how do I attach custom code for exporting report to PDF to the export button on the CrystalReportViewer control toolbar?

Thanks for your usual assistance

Paul Aziz

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Hi Paul,

If its a web app, try adding the report object to a HTTP session before assigning it to the viewer in code. This might fix the error. A lot depends on the code.

Now, answeres to your queries.

I am not sure If I understood this correctly but to export the report from viewer's export button we do not nee any custom code. Simply view the report in viewer and click the print button. You could wrtie the code to assign the reportsource to the viewer or use the viewer control;s property 'ReportSource'.


As there are limited customizations possible with the viewer, we can not attach custom code to viewers export button. However, you could hide the viewer export button and create your own export button using the SDK.

1592578 - How to disable/hide individual buttons in the Crystal Reports .NET Windows Form viewer


You will have to create your own export button and code the export options you want to see. A good example is vbnet_win_export.zip available from here:

Crystal Reports for .NET SDK Samples - Business Intelligence (BusinessObjects) - SCN Wiki

Also, with CR for VS SDK you could chhose the export formats you want to display with Viewer export button.

Search the forum, a lot of info is available on this topic.

Thanks,

Bhushan

paul_aziz
Explorer
0 Kudos

Hi, thanks for your reply.

It is not web app; it is desptop and I think it will be helpful to provide the code for displaying the report.

The code is shown below

ds = New db_asfDataSet
        datBr = New db_asfDataSetTableAdapters.get_all_branchesTableAdapter
        datBr.Fill(ds.get_all_branches)
        Dim rpt As New branch_rpt
        rpt.SetDataSource(ds)
        CrystalReportViewer1.ReportSource = rpt
former_member183750
Active Contributor
0 Kudos

That should work. What Service pack are you using? What version of .NET?

Try this code:

Imports CrystalDecisions.CrystalReports.Engine

ds = New db_asfDataSet

datBr = New db_asfDataSetTableAdapters.get_all_branchesTableAdapter

datBr.Fill(ds.get_all_branches)

Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument

        crReportDocument.Load(<path to report>)

        crReportDocument.SetDataSource(ds)

        CrystalReportViewer1.ReportSource = crReportDocument

    End Sub

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow me on Twitter

paul_aziz
Explorer
0 Kudos

Hi,

I will try your suggestion and give feedback asp

I am using version 13.0.10.13 and  4.5 .NET

Thanks

Paul Aziz

paul_aziz
Explorer
0 Kudos

It did not work.

Same error: 'object reference to an instance of an object'

The code is show below so you can examine it

ds = New db_asfDataSet

                datBr = New db_asfDataSetTableAdapters.get_all_branchesTableAdapter

                datBr.Fill(ds.get_all_branches)

                Dim SS As String = Application.StartupPath

                Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument

                crReportDocument.Load(Application.StartupPath & "\branch_rpt.rpt")

                'crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"))

                crReportDocument.SetDataSource(ds)

                CrystalReportViewer1.ReportSource = crReportDocument

Thanks

paul_aziz
Explorer
0 Kudos

Hello snr.

What I mean is that I have seen several export implementations use custom code such in the sites below.

But want to just allow user to export the report  by simply clicking the expor button on reportviewer.

What I mean is: 'is there a requirement for custom code(i.e. export handler) other than one for loading and displaying the report?'

If there is how do I associate this handler with viewer export button so when user clicks viewer export button the export handler will activated

former_member183750
Active Contributor
0 Kudos

Is your code under Page Load?

See if the code in the sample app "vbnet_win_exporttopdf.zip: works for you. The sample app can be downloaded from here:

Crystal Reports for .NET SDK Samples - Business Intelligence (BusinessObjects) - SCN Wiki

- Ludek

Message was edited by: Ludek Uher

paul_aziz
Explorer
0 Kudos

Thanks so much snr.

Yes I have my code under Page Load.

I just got it fixed. The problem is I used one form and reportviewer for displaying my reports. In the form I created custom enum and procedure to determine user selection at runtime and display the approapriate report accordingly.

When I created separate forms for each report I was able to export them without any problems. Below is a section of the code that did not work showing

If selectedReport=ReportType.Branches then

  ds = New db_asfDataSet

            datPmt = New db_asfDataSetTableAdapters.get_all_branchesTableAdapter

            datPmt.Fill(ds.get_all_branches)

            Dim rpt As New branch_rpt

            rpt.SetDataSource(ds)

            CrystalReportViewer1.ReportSource = rpt

ElseIf selectedReport=ReportType.Customers Then

         datPmt = New db_asfDataSetTableAdapters.get_all_customersTableAdapter

            datPmt.Fill(ds.get_all_customers)

            Dim rpt As New custs

            rpt.SetDataSource(ds)

            CrystalReportViewer1.ReportSource = rpt

...

End If

Thanks so much for your assistance

Answers (0)