TAGS: aspx, .net, parse error
TAGS: crystal reports, .net, toolbar, export, print
'aspnet_client\system_web\2_0_50727\CrystalReportWebFormViewer3'.. along with the typical sub-directories (css, html, images, images\toolbar, images\tree, js) and their respective files.
TAGS: aspx, .net, crystal reports
href="../ReportViewer.aspx?crDB=database&crRPT=report&rptVar=1"
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Partial Class ReportViewer
Inherits System.Web.UI.Page
'How to use:
'ReportViewer.aspx?crDB=myDatabase&crRPT=myReport&rptVar=1
'crDB = Database
'crRPT = Report (Do NOT include the .rpt extension)
'Remaining parameters, rptVar in this case, will be passed to the report
'WARNING: Passing a variable the report is not setup to handle will cause an error
'Var to hold a single report
Public oReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim crDB As String 'URL passed DB Name
Dim crRPT As String 'URL passed Report Name
Dim defaultSRV As String 'Default Server
Dim defaultID As String 'Default User ID
Dim defaultPW As String 'Default Password
Dim defaultDB As String 'Default DB Name
Dim defaultPATH As String 'Default Report Path
Dim defaultRPT As String 'Default Report Name
'defaultDB & defaultRPT are not required, however, if they are included, you
'will NOT have to specify the crDB & crRPT variables for that report in the URL.
'You could simply use: "ReportViewer.aspx?rptVar=1" instead.
defaultSRV = "server" 'Default Server
defaultID = "userid" 'Default User ID
defaultPW = "password" 'Default Password
defaultDB = "database" 'Default DB Name
defaultPATH = "c:\reports\" 'Default Report Path
defaultRPT = "report.rpt" 'Default Report Name
crDB = Request.QueryString.Item("crDB") 'Database to link to for CR
crRPT = Request.QueryString.Item("crRPT") 'Report name and sub-path if required
'Set a default database or use specified
If crDB Is Nothing Then
crDB = defaultDB
End If
'Set a default report or use specified
If crRPT Is Nothing Then
crRPT = defaultPATH & defaultRPT
Else
crRPT = defaultPATH & crRPT & ".rpt"
End If
'Process a report (Load, Login, View)
oReport.Load(crRPT)
DoCRLogin(defaultSRV, crDB, defaultID, defaultPW, oReport)
CrystalReportViewer1.ReportSource = oReport
End Sub
Public Sub PassQStoCR()
'Parse QueryString and pass to Crystal Reports
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection
'Load variables into NameValueCollection
coll = Request.QueryString
'Place key names into an array
arr1 = coll.AllKeys
For loop1 = 0 To arr1.GetUpperBound(0)
'Get all values under this key.
arr2 = coll.GetValues(loop1)
For loop2 = 0 To arr2.GetUpperBound(0)
'Two loops to ignore the passed DB & Report variables
If Not Server.HtmlEncode(arr1(loop1)) = "crDB" Then
If Not Server.HtmlEncode(arr1(loop1)) = "crRPT" Then
oReport.SetParameterValue(Server.HtmlEncode(arr1(loop1)), _
Server.HtmlEncode(arr2(loop2)))
End If
End If
Next loop2
Next loop1
End Sub
Public Sub DoCRLogin(ByVal crSRV As Object, ByVal crDB As Object, ByVal crID As Object, _
ByVal crPW As Object, ByRef oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim _applyLogin As New ApplyCRLogin
PassQStoCR() 'Read QS and pass vars to CR
'Use ApplyLogin object to apply login info to all tables in CR object
_applyLogin._dbName = crDB
_applyLogin._passWord = crPW
_applyLogin._serverName = crSRV
_applyLogin._userID = crID
_applyLogin.ApplyInfo(oRpt)
'Clean up
_applyLogin = Nothing
End Sub
Public Class ApplyCRLogin
Public _dbName As String
Public _serverName As String
Public _userID As String
Public _passWord As String
Public Sub ApplyInfo(ByRef _oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim oCRDb As CrystalDecisions.CrystalReports.Engine.Database = _oRpt.Database
Dim oCRTables As CrystalDecisions.CrystalReports.Engine.Tables = oCRDb.Tables
Dim oCRTable As CrystalDecisions.CrystalReports.Engine.Table
Dim oCRTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim oCRConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
oCRConnectionInfo.DatabaseName = _dbName
oCRConnectionInfo.ServerName = _serverName
oCRConnectionInfo.UserID = _userID
oCRConnectionInfo.Password = _passWord
For Each oCRTable In oCRTables
oCRTableLogonInfo = oCRTable.LogOnInfo
oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo
oCRTable.ApplyLogOnInfo(oCRTableLogonInfo)
Next
End Sub
End Class
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
oReport.Dispose()
End Sub
End Class