I have downloaded the sample from Crystaldescisions. Their sample works fine on my machine. Mine gives me a login error. I have basically pasted their code into my project.
the differences are theirs is an access Database. Mine is a SQL database. The SQL logon works initailly at least because I can see data in the report.
I am connecting to 1 tabel in the SQL database only.
It seems to fail when it gets to the TRY section of the export report function.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Public Class export2
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
' CR Variables
Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
'Create an instance of the strongly-typed report object
' *******************************************
' Initialize Dropdownlist for Format types
' *******************************************
With DropDownList1.Items
.Add(""
.Add("Rich Text (RTF)"
.Add("Portable Document (PDF)"
.Add("MS Word (DOC)"
.Add("MS Excel (XLS)"
.Add("Crystal Report (RPT)"
.Add("HTML 3.2 (HTML)"
.Add("HTML 4.0 (HTML)"
End With
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim logOnInfo As New CrystalDecisions.Shared.TableLogOnInfo()
'Dim oRpt As New RPTexporttest()
'CrystalReportViewer1.ReportSource = oRpt
crReportDocument = New RPTexporttest()
CrystalReportViewer1.ReportSource = crReportDocument
crReportDocument = crReportDocument
logOnInfo = crReportDocument.Database.Tables.Item("t_server_info".LogOnInfo
logOnInfo.ConnectionInfo.Password = "PASSWORD"
CrystalReportViewer1.LogOnInfo.Add(logOnInfo)
End Sub
Sub ExportReport()
' This subroutine uses a case statement to determine the selected export format from the dropdownlist
' menu and then sets the appropriate export options for the selected export format. The report is
' exported to a subdirectory called "Exported".
' ********************************
'Check to see if the application directory has a subdirectory called "Exported".
'If not, create the directory since exported files will be placed here.
'This uses the Directory class of the System.IO namespace.
Dim ExportPath As String
ExportPath = "c:\oktodel\srts\"
'If Directory.Exists(ExportPath) = False Then
'Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\"
'End If
' ********************************
' First we must create a new instance of the diskfiledestinationoptions class and
' set variable called crExportOptions to the exportoptions class of the reportdocument.
crDiskFileDestinationOptions = New DiskFileDestinationOptions()
crExportOptions = crReportDocument.ExportOptions
'Find the export type specified in the dropdownlist and export the report. The possible export format
'types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT),
'HTML 3.2 (HTML) and HTML 4.0 (HTML)
'
'Though not used in this sample application, there are options that can be specified for various format types.
'When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
'first page, last page or page range to be exported.
'When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
'the column width etc.
Select Case DropDownList1.SelectedItem.Text 'this contains the value of the selected export format.
Case "Rich Text (RTF)"
'--------------------------------------------------------------------
'Export to RTF.
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.RichText
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "Portable Document (PDF)"
'Export to PDF
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf"
'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "MS Word (DOC)"
'Export to Word
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "MS Excel (XLS)"
'Export to Excel
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "Crystal Report (RPT)"
'Export to Crystal reports:
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.CrystalReport
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "HTML 3.2 (HTML)"
'Export to HTML32:
Dim HTML32Formatopts As New HTMLFormatOptions()
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML32
End With
With HTML32Formatopts
.HTMLBaseFolderName = ExportPath + "Html32Folder" 'Foldername to place HTML files
.HTMLFileName = "HTML32.html"
.HTMLEnableSeparatedPages = False
.HTMLHasPageNavigator = False
End With
crExportOptions.FormatOptions = HTML32Formatopts
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "HTML 4.0 (HTML)"
'Export to Html 4.0:
Dim HTML40Formatopts As New HTMLFormatOptions()
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML40
End With
With HTML40Formatopts
.HTMLBaseFolderName = ExportPath + "Html40Folder" ' Foldername to place HTML files
.HTMLFileName = "HTML40.html"
.HTMLEnableSeparatedPages = True
.HTMLHasPageNavigator = True
.FirstPageNumber = 1
.LastPageNumber = 3
End With
crExportOptions.FormatOptions = HTML40Formatopts
End Select 'export format
'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
Try
' Export the report
crReportDocument.Export()
Catch err As Exception
Response.Write("<BR>"
Response.Write(err.Message.ToString)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ExportReport()
End Sub
End Class
the differences are theirs is an access Database. Mine is a SQL database. The SQL logon works initailly at least because I can see data in the report.
I am connecting to 1 tabel in the SQL database only.
It seems to fail when it gets to the TRY section of the export report function.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Public Class export2
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
' CR Variables
Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
'Create an instance of the strongly-typed report object
' *******************************************
' Initialize Dropdownlist for Format types
' *******************************************
With DropDownList1.Items
.Add(""
.Add("Rich Text (RTF)"
.Add("Portable Document (PDF)"
.Add("MS Word (DOC)"
.Add("MS Excel (XLS)"
.Add("Crystal Report (RPT)"
.Add("HTML 3.2 (HTML)"
.Add("HTML 4.0 (HTML)"
End With
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim logOnInfo As New CrystalDecisions.Shared.TableLogOnInfo()
'Dim oRpt As New RPTexporttest()
'CrystalReportViewer1.ReportSource = oRpt
crReportDocument = New RPTexporttest()
CrystalReportViewer1.ReportSource = crReportDocument
crReportDocument = crReportDocument
logOnInfo = crReportDocument.Database.Tables.Item("t_server_info".LogOnInfo
logOnInfo.ConnectionInfo.Password = "PASSWORD"
CrystalReportViewer1.LogOnInfo.Add(logOnInfo)
End Sub
Sub ExportReport()
' This subroutine uses a case statement to determine the selected export format from the dropdownlist
' menu and then sets the appropriate export options for the selected export format. The report is
' exported to a subdirectory called "Exported".
' ********************************
'Check to see if the application directory has a subdirectory called "Exported".
'If not, create the directory since exported files will be placed here.
'This uses the Directory class of the System.IO namespace.
Dim ExportPath As String
ExportPath = "c:\oktodel\srts\"
'If Directory.Exists(ExportPath) = False Then
'Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\"
'End If
' ********************************
' First we must create a new instance of the diskfiledestinationoptions class and
' set variable called crExportOptions to the exportoptions class of the reportdocument.
crDiskFileDestinationOptions = New DiskFileDestinationOptions()
crExportOptions = crReportDocument.ExportOptions
'Find the export type specified in the dropdownlist and export the report. The possible export format
'types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT),
'HTML 3.2 (HTML) and HTML 4.0 (HTML)
'
'Though not used in this sample application, there are options that can be specified for various format types.
'When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
'first page, last page or page range to be exported.
'When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
'the column width etc.
Select Case DropDownList1.SelectedItem.Text 'this contains the value of the selected export format.
Case "Rich Text (RTF)"
'--------------------------------------------------------------------
'Export to RTF.
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.RichText
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "Portable Document (PDF)"
'Export to PDF
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf"
'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "MS Word (DOC)"
'Export to Word
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "MS Excel (XLS)"
'Export to Excel
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "Crystal Report (RPT)"
'Export to Crystal reports:
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.CrystalReport
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "HTML 3.2 (HTML)"
'Export to HTML32:
Dim HTML32Formatopts As New HTMLFormatOptions()
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML32
End With
With HTML32Formatopts
.HTMLBaseFolderName = ExportPath + "Html32Folder" 'Foldername to place HTML files
.HTMLFileName = "HTML32.html"
.HTMLEnableSeparatedPages = False
.HTMLHasPageNavigator = False
End With
crExportOptions.FormatOptions = HTML32Formatopts
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "HTML 4.0 (HTML)"
'Export to Html 4.0:
Dim HTML40Formatopts As New HTMLFormatOptions()
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML40
End With
With HTML40Formatopts
.HTMLBaseFolderName = ExportPath + "Html40Folder" ' Foldername to place HTML files
.HTMLFileName = "HTML40.html"
.HTMLEnableSeparatedPages = True
.HTMLHasPageNavigator = True
.FirstPageNumber = 1
.LastPageNumber = 3
End With
crExportOptions.FormatOptions = HTML40Formatopts
End Select 'export format
'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
Try
' Export the report
crReportDocument.Export()
Catch err As Exception
Response.Write("<BR>"
Response.Write(err.Message.ToString)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ExportReport()
End Sub
End Class