Vb.net – Export crystal report into pdf in vb without using form

crystal-reportsvb.netvisual studio 2010

I'm a newbie to VB and Crystal Reports.

I want to make an .exe file in VB.NET that doesn't use a Form.

I'm using Visual Studio 2010.
The .exe file is just purely for exporting a Crystal Report into a .pdf file, where should I start?

Should I use the console application?

Should I use the empty project code?

I have searched the internet and cannot find any references.

Please let me know if there is a Reference that I can refer to.

Best Answer

You could probably use a console app or a forms app but just don't display the form. I tend to point people to the code samples at: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_export_pdf.htm

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
    Dim cryRpt As New ReportDocument

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New _
            DiskFileDestinationOptions()
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            CrDiskFileDestinationOptions.DiskFileName = _
                                        "c:\crystalExport.pdf"
            CrExportOptions = cryRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            cryRpt.Export()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class
Related Topic