HI i'm in a bit of a rush so sorry for the breif post.
I'm posting a chunk of code i have used and works to a degree, but i'm in
the process of trying to migrate to SQL Reporting Services.
Hopefully you can work your way through the logic (it isn't pretty but it
works in a production environment!)
Imports CrystalDecisions.Shared
Public Class AdobePrint
Inherits System.Web.UI.Page
#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()
If Not Session("ReportLoc") Is Nothing Then
Dim FileName As String
Dim ExportPath As String
Dim dfdOptions As DiskFileDestinationOptions
Dim ExportOpts As ExportOptions
Dim OutputURL As String
Dim myreport As New ReportDocument()
If Not Session("ReportLoc") Is Nothing Then
FileName = Session("ReportLoc")
' FileName = FileName.Replace("Crystal_Reports", "Adobe_Reports")
If viewstate("ReportDoc") Is Nothing Then
viewstate.Add("ReportDoc", myreport)
myreport.Load(FileName)
SetDatabase(myreport)
SetParmaeters(myreport)
SetSelectionFourmula(myreport)
ExportPath = (Server.MapPath("AdobePrint.aspx").Replace("AdobePrint.aspx",
"")) & "temp\" & Session("Username") & ".pdf"
'OutputFile = Server.MapPath("..\Reports\ExportedReports\" &
txtFileName.Text & OutputFileExtension)
OutputURL = "./temp/" & Session("Username") & ".pdf"
'Session.SessionID.ToString
dfdOptions = New DiskFileDestinationOptions
dfdOptions.DiskFileName = ExportPath
ExportOpts = myreport.ExportOptions
With ExportOpts
..DestinationOptions = dfdOptions
..ExportDestinationType = .ExportDestinationType.DiskFile
..ExportFormatType = .ExportFormatType.PortableDocFormat
End With
myreport.Export()
'With Response
' .ClearContent()
' .ClearHeaders()
' .ContentType = "application/pdf"
' .WriteFile(ExportPath)
' .Write("<HTML><HTML>")
' .Flush()
' .Close()
'End With
' System.IO.File.Delete(ExportPath)
Session.Remove("ReportLoc")
Response.Redirect(OutputURL)
End If
End If
End If
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
End Sub
Private Sub SetParmaeters(ByRef myreport As ReportDocument)
' If Not (Session("ReportDataDef") Is Nothing) Then
' 'Dim Param As CrystalDecisions.Shared.ParameterValues
' Dim DataDef As CrystalDecisions.CrystalReports.Engine.DataDefinition =
Session("ReportDataDef")
' Dim ParamFields As
CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
' Dim ParamFD As ParameterFieldDefinition
' Dim ParamDis As New ParameterDiscreteValue()
' Dim i As Integer
' ParamFields = DataDef.ParameterFields
' For i = 0 To ParamFields.Count - 1
' myReport.DataDefinition.ParameterFields.apply()
'..CurrentValues(0) = ParamFields(i).CurrentValues(0)
' Next
' End If
If Not (Session("ReportDataDef") Is Nothing) Then
Dim DataDef As CrystalDecisions.CrystalReports.Engine.DataDefinition =
Session("ReportDataDef")
Dim ParamFields As ParameterFieldDefinitions
Dim paramValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim i As Integer
ParamFields = DataDef.ParameterFields
For i = 0 To ParamFields.Count - 1
paramValues = ParamFields(i).CurrentValues
myReport.DataDefinition.ParameterFields.Item(i).ApplyCurrentValues(paramValues)
Next
End If
End Sub
Private Sub SetSelectionFourmula(ByRef myreport As ReportDocument)
If Not (Session("ReportDataDef") Is Nothing) Then
Dim DataDef As CrystalDecisions.CrystalReports.Engine.DataDefinition =
Session("ReportDataDef")
myReport.DataDefinition.RecordSelectionFormula =
DataDef.RecordSelectionFormula
End If
End Sub
Private Sub SetDatabase(ByRef myreport As ReportDocument)
Dim CCI As Global.CrystalConnection = Application("CrystalDBInfo")
Dim RPTConnInfo As New ConnectionInfo()
With RPTConnInfo
..ServerName = CCI.Servername
..DatabaseName = CCI.Database
..UserID = CCI.UserID
..Password = CCI.PW
End With
Dim tblLogOnInfo As New TableLogOnInfo()
Dim myDB = myReport.Database
Dim myTbl = myDB.tables
Dim tbl As CrystalDecisions.CrystalReports.Engine.Table
For Each tbl In myReport.Database.Tables
tblLogOnInfo = tbl.LogOnInfo
tblLogOnInfo.ConnectionInfo = RPTConnInfo
tbl.ApplyLogOnInfo(tblLogOnInfo)
Next
End Sub
End Class