Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim crReportDocument1 As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
'+-------------------------+
'| CREATE NAME OF PDF FILE |
'+-------------------------+
Dim Fname As String
Fname = "C:\EXPORTS\" & Session.SessionID.ToString & ".pdf"
'+--------------------------+
'| INITIALIZE REPORT OBJECT |
'+--------------------------+
crReportDocument1 = New ReportDocument
crReportDocument1.Load("C:\inetpub\wwwroot\CRTEST\RAInformation_ORIG.RPT")
'+-----------------+
'| SQL SERVER INFO |
'+-----------------+
crConnectionInfo = New ConnectionInfo
With crConnectionInfo
.ServerName = "SQLMAIN"
.DatabaseName = "RMA"
.UserID = "USER1"
.Password = "TESTDATA"
End With
'+------------------------------------------+
'| GET TABLES COLLECTION FROM REPORT OBJECT |
'+------------------------------------------+
crDatabase = crReportDocument1.Database
crTables = crDatabase.Tables
'+-------------------------+
'| APPLY LOGIN INFORMATION |
'+-------------------------+
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
'+---------------------------+
'| INITIALIZE EXPORT OPTIONS |
'+---------------------------+
crDiskFileDestinationOptions = New DiskFileDestinationOptions
crDiskFileDestinationOptions.DiskFileName = Fname
crExportOptions = crReportDocument1.ExportOptions
'+------------------------------------------------+
'| INITILIZE PARAMETER FIELD AND VALUE COLLECTION |
'+------------------------------------------------+
Dim crParamFields As ParameterFieldDefinitions = crReportDocument1.DataDefinition.ParameterFields
Dim crParamField As ParameterFieldDefinition ' Crystal Parameter Field
Dim crParamValues As ParameterValues ' Crystal Parameter Values Collection
Dim crParamValue As ParameterDiscreteValue ' Crystal Parameter Value
'+---------------------+
'| SET PARAMETER VALUE |
'+---------------------+
crParamField = crParamFields(0) ' Get Parameter Field
crParamValues = crParamField.CurrentValues ' Get Current Values
crParamValue = New ParameterDiscreteValue ' Instanciate New Discrete Value
crParamValue.Value = "16040050" ' Set Discrete Value
crParamValues.Add(crParamValue) ' Add Value to CurrentValues Collection
crParamField.ApplyCurrentValues(crParamValues) ' Apply Value Changes
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.DestinationOptions = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With
'+--------+
'| EXPORT |
'+--------+
crReportDocument1.Export() '<---- ERROR HERE
'+-----------------+
'| SEND TO BROWSER |
'+-----------------+
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(Fname)
'+---------+
'| CLEANUP |
'+---------+
Response.Flush()
Response.Close()
System.IO.File.Delete(Fname)
End Sub