on 05-22-2015 3:31 AM
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:
Thanks for your usual assistance
Paul Aziz
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 |
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
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
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
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
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
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.