i want to export crsytal report to PDF format, but i got error below is the error:
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:
Line 61: myDiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
Line 62: myDiskFileDestinationOptions.DiskFileName = myExportFile
Line 63: myExportOptions = orptPDF.ExportOptions Line 64:
Line 65: With myExportOptions
i need help from expertise here to resolve this problem....i'm new in this concept
i got error when i want to export my report to PDF file, below is my full code, i can show you the error, because the error appear in message box.
what sholud i do now
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim getSessionKategori As Object
Dim getSessionSubKategori As Object
getSessionKategori = Session("kategori")
getSessionSubKategori = Session("subkes")
'Dim getSessionKategori As String = "Kenalan"
'Dim getSessionSubKategori As String = "Keluar Kawasan Sekolah"
Dim rptDoc As New ReportDocument
Dim ds As New DataSet2
Dim mySQLConnection = New SqlConnection()
Dim dt As New DataTable
dt.TableName = "Senarai Kesalahan"
mySQLConnection.ConnectionString = ConfigurationManager.ConnectionStrings("default").ConnectionString
Dim da As New SqlDataAdapter("SELECT MaklumatPelajar.Nama,MaklumatPelajar.NoIc,KesalahanDisiplin.KategoriKes,KesalahanDisiplin.SubKes,KesalahanDisiplin.TarikhKes,KesalahanDisiplin.AduanOleh" & _
" FROM MaklumatPelajar INNER JOIN KesalahanDisiplin ON MaklumatPelajar.IdPelajar = KesalahanDisiplin.IdPelajar" & _
" WHERE KesalahanDisiplin.KategoriKes = '" & getSessionKategori & "' AND KesalahanDisiplin.SubKes = '" & getSessionSubKategori & "'", mySQLConnection)
da.Fill(dt)
ds.Tables(0).Merge(dt)
rptDoc.Load(Server.MapPath("SenaraiKesalahan.rpt"))
rptDoc.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rptDoc
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cryRpt As ReportDocument
cryRpt = New ReportDocument()
CrystalReportViewer1.ReportSource = cryRpt
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "C:\exports\csharp.net-informations.pdf"
CrExportOptions = cryRpt.ExportOptions
If True Then
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
CrExportOptions.FormatOptions = CrFormatTypeOptions
End If
cryRpt.Export()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try '
End Sub
CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Invalid report file path. at CrystalDecisions.CrystalReports.Engine.EngineExceptionUtils.DoThrowException(String message, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ExceptionThrower.ThrowEngineException(String
messageID, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) at CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_FormatEngine()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ExportOptions() at ReportSenaraiKesalahan.Button1_Click(Object sender, EventArgs e) in C:\Application Check IC\13-11-2012\Application\ReportSenaraiKesalahan.aspx.vb:line 72
again i attach to you the code for export
cryRpt = New ReportDocument()
CrystalReportViewer1.ReportSource = cryRpt
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "C:\exports"
CrExportOptions = cryRpt.ExportOptions
If True Then
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
CrExportOptions.FormatOptions = CrFormatTypeOptions
End If
cryRpt.Export()
Catch ex As Exception
Label1.Text = ex.ToString()
End Try '
after try so many times, i still can't export crystal report to pdf format below is the code and error
cryRpt = New ReportDocument()
CrystalReportViewer1.ReportSource = cryRpt
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "c:\crystalExport.pdf"
CrExportOptions = cryRpt.ExportOptions
If True Then
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
CrExportOptions.FormatOptions = CrFormatTypeOptions
End If
cryRpt.Export()
Catch ex As Exception
Label1.Text = ex.ToString()
End Try
Error
CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Invalid report file path. at CrystalDecisions.CrystalReports.Engine.EngineExceptionUtils.DoThrowException(String message, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ExceptionThrower.ThrowEngineException(String
messageID, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) at CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_FormatEngine()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ExportOptions() at ReportSenaraiKesalahan.Button1_Click(Object sender, EventArgs e) in C:\Application Check IC\13-11-2012\Application\ReportSenaraiKesalahan.aspx.vb:line 74
afastars
Member
52 Points
221 Posts
Export Crystal Report To PDF Format
Nov 27, 2012 12:21 AM|LINK
i want to export crsytal report to PDF format, but i got error below is the error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 61: myDiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions() Line 62: myDiskFileDestinationOptions.DiskFileName = myExportFile Line 63: myExportOptions = orptPDF.ExportOptions Line 64: Line 65: With myExportOptionsi need help from expertise here to resolve this problem....i'm new in this concept
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 04:34 AM|LINK
form an error, it's clear one of 'myExportOptions' or 'orptPDF' object is not yet initialized.
check this code, this will help you to export in pdf
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-export-pdf.htm
MCP
afastars
Member
52 Points
221 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 08:54 AM|LINK
hai santosh.jagdale
i got error when i want to export my report to PDF file, below is my full code, i can show you the error, because the error appear in message box.
what sholud i do now
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender Dim getSessionKategori As Object Dim getSessionSubKategori As Object getSessionKategori = Session("kategori") getSessionSubKategori = Session("subkes") 'Dim getSessionKategori As String = "Kenalan" 'Dim getSessionSubKategori As String = "Keluar Kawasan Sekolah" Dim rptDoc As New ReportDocument Dim ds As New DataSet2 Dim mySQLConnection = New SqlConnection() Dim dt As New DataTable dt.TableName = "Senarai Kesalahan" mySQLConnection.ConnectionString = ConfigurationManager.ConnectionStrings("default").ConnectionString Dim da As New SqlDataAdapter("SELECT MaklumatPelajar.Nama,MaklumatPelajar.NoIc,KesalahanDisiplin.KategoriKes,KesalahanDisiplin.SubKes,KesalahanDisiplin.TarikhKes,KesalahanDisiplin.AduanOleh" & _ " FROM MaklumatPelajar INNER JOIN KesalahanDisiplin ON MaklumatPelajar.IdPelajar = KesalahanDisiplin.IdPelajar" & _ " WHERE KesalahanDisiplin.KategoriKes = '" & getSessionKategori & "' AND KesalahanDisiplin.SubKes = '" & getSessionSubKategori & "'", mySQLConnection) da.Fill(dt) ds.Tables(0).Merge(dt) rptDoc.Load(Server.MapPath("SenaraiKesalahan.rpt")) rptDoc.SetDataSource(ds) CrystalReportViewer1.ReportSource = rptDoc End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cryRpt As ReportDocument cryRpt = New ReportDocument() CrystalReportViewer1.ReportSource = cryRpt Try Dim CrExportOptions As ExportOptions Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions() Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions() CrDiskFileDestinationOptions.DiskFileName = "C:\exports\csharp.net-informations.pdf" CrExportOptions = cryRpt.ExportOptions If True Then CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions CrExportOptions.FormatOptions = CrFormatTypeOptions End If cryRpt.Export() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try ' End Subsantosh.jagd...
Star
7625 Points
1454 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 09:18 AM|LINK
if above is your full code, then where is below line?
Line 63: myExportOptions = orptPDF.ExportOptions
i would suggest debug the code and check why object is null.
MCP
afastars
Member
52 Points
221 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 09:32 AM|LINK
hai santosh
the error is below:
CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Invalid report file path. at CrystalDecisions.CrystalReports.Engine.EngineExceptionUtils.DoThrowException(String message, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ExceptionThrower.ThrowEngineException(String messageID, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) at CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_FormatEngine() at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ExportOptions() at ReportSenaraiKesalahan.Button1_Click(Object sender, EventArgs e) in C:\Application Check IC\13-11-2012\Application\ReportSenaraiKesalahan.aspx.vb:line 72
again i attach to you the code for export
cryRpt = New ReportDocument() CrystalReportViewer1.ReportSource = cryRpt Try Dim CrExportOptions As ExportOptions Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions() Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions() CrDiskFileDestinationOptions.DiskFileName = "C:\exports" CrExportOptions = cryRpt.ExportOptions If True Then CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions CrExportOptions.FormatOptions = CrFormatTypeOptions End If cryRpt.Export() Catch ex As Exception Label1.Text = ex.ToString() End Try 'santosh.jagd...
Star
7625 Points
1454 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 10:02 AM|LINK
oh! your error is changed.
please check report file path, it should be valid path.
MCP
jaya kumar
Member
367 Points
103 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 10:04 AM|LINK
Hi
http://www.codeproject.com/Articles/14549/Crystal-Reports-To-PDF-converter-Without-Crystal-R
http://www.codeproject.com/Articles/14597/Convert-a-Crystal-Report-to-PDF
http://vb.net-informations.com/crystal-report/vb.net_crystal_report_export_pdf.htm
afastars
Member
52 Points
221 Posts
Re: Export Crystal Report To PDF Format
Nov 27, 2012 10:21 AM|LINK
hi santosh.jagdale and jaya kumar
i need more time to analys and try to resolve it...will update both of you my progress....currently i'm working on that
afastars
Member
52 Points
221 Posts
Re: Export Crystal Report To PDF Format
Nov 28, 2012 07:13 AM|LINK
after try so many times, i still can't export crystal report to pdf format below is the code and error
cryRpt = New ReportDocument() CrystalReportViewer1.ReportSource = cryRpt Try Dim CrExportOptions As ExportOptions Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions() Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions() CrDiskFileDestinationOptions.DiskFileName = "c:\crystalExport.pdf" CrExportOptions = cryRpt.ExportOptions If True Then CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions CrExportOptions.FormatOptions = CrFormatTypeOptions End If cryRpt.Export() Catch ex As Exception Label1.Text = ex.ToString() End TryError
CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Invalid report file path. at CrystalDecisions.CrystalReports.Engine.EngineExceptionUtils.DoThrowException(String message, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ExceptionThrower.ThrowEngineException(String messageID, EngineExceptionErrorID id) at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) at CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_FormatEngine() at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ExportOptions() at ReportSenaraiKesalahan.Button1_Click(Object sender, EventArgs e) in C:\Application Check IC\13-11-2012\Application\ReportSenaraiKesalahan.aspx.vb:line 74
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Export Crystal Report To PDF Format
Nov 29, 2012 10:13 AM|LINK
if you not, please set reprot file path. as below
string strRptLoad = Server.MapPath("~/Reports/PayDetails.rpt");Also go through http://forums.asp.net/t/1776249.aspx/1
MCP