Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET - Report Logon

Status
Not open for further replies.

DallasAggie

Programmer
Oct 24, 2002
98
US
----------------------------------------
- Visual Studio .NET 2003
- Web application using VB.NET
- Crystal Enterprise 10
- Crystal Reports 9 Developer Edition
----------------------------------------

Okay all. I'm running into an issue with my ASP.NET application. There are hundreds of forums that talk about my issue, but the method I am using doesn't apply.

I'm not sure if I'll be able to explain this corectly, so please forgive me.

The problem with most code I've seen is that they've been using the ReportDocument to Load a report...in turn, obtaining the number of tables. I'm not using the ReportDocument, so I don't have a way to Example:
Code:
[b] not using this method[/b]

crReportDocument.Load("C:\\CrystalReport1.rpt")

When the user logs in to the main site (custom ePortfolio style in .NET), the see a list of reports, when the click view, it passes (viewreport.aspx) the session object, report id to the InfoStore to return a report instance -- in this case, it would be an "on demand" report. The report instance is then passed into the viewer report source ... this works great on reports that don't require a user name/password into a database, but I need to pass it into reports that do require it.

Code:
Imports CrystalDecisions.Enterprise
Imports CrystalDecisions.Enterprise.Desktop
'Imports CrystalDecisions.Shared
'Imports CrystalDecisions.CrystalReports.Engine
'Imports CrystalDecisions.ReportAppServer.ClientDoc
Imports System.Text
Imports System
Imports System.Web
Imports System.IO


' <summary>
' The ViewReport class uses the web display functionality of the CrystalDecisions.Web.CrystalReportViewer
' class to display the report on the page. The CrystalReportViewer instance must be assigned a report
' source during the page init method (not the page load method). Therefore the code for this class is
' found inside the 'web form designer generated code' region.
' </summary>
Public Class ViewReport
    Inherits System.Web.UI.Page

    Protected WithEvents myCrystalReportViewer As CrystalDecisions.Web.CrystalReportViewer
    Protected WithEvents viewListing As System.Web.UI.WebControls.HyperLink
    Protected WithEvents pnl_ReportViewer As System.Web.UI.WebControls.Panel

    Private myEnterpriseSession As EnterpriseSession
    Private myInfoStore As InfoStore
    Dim ceEnterpriseService As EnterpriseService

    Dim strSubreportname As String
    Private reportID As String
    Private folderID As String


#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    ' <summary>
    ' The class level EnterpriseSession variable is assigned its value from the Session instance.
    ' The reportID variable is assigned from the Request.QueryString method. The CrystalReportViewer
    ' instance is associated with an enterprise logon by assigning its EntepriseLogon property to the
    ' EnterpriseSession instance. Finally, the ReportSource property of the CrystalReportViewer instance
    ' is assigned to an ISCRReportSource interface that is retrieved from the RetrieveReportSource
    ' method of the Utilities class.
    ' </summary>
    ' <param name="e">event arguments</param>
    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.
        myEnterpriseSession = CType(Session("EnterpriseSession"), EnterpriseSession)
        myInfoStore = CType(Session("InfoStore"), InfoStore)

        reportID = Request.QueryString("reportID")
        folderID = Request.QueryString("folderID")

        Dim query As String = "Select SI_CUID, SI_PROGID, SI_FILES from CI_INFOOBJECTS where SI_ID=" + reportID
        Dim myInfoObjects As InfoObjects = myInfoStore.Query(query)
        Dim myInfoObject As InfoObject = myInfoObjects(1)
        Dim myFile As InfoObject = myInfoObjects.Item(1)

        folderID = Request.QueryString("folderID")

        Select Case myInfoObject.GetType.Name
            Case "Report"

                Try
                    myCrystalReportViewer.Visible = True
                    myCrystalReportViewer.EnterpriseLogon = myEnterpriseSession
                    myCrystalReportViewer.ReportSource = Utilities.RetrieveReportSource(myInfoStore, reportID)

                Catch ex As Exception
                    myCrystalReportViewer.Visible = False
                End Try



            Case "Pdf"
                Dim myFileArray As Byte()
                Dim myReport As Pdf = CType(myFile, Pdf)
                Dim pdfObject As System.Object = myReport.ByteStream
                myFileArray = CType(pdfObject, Byte())

                Response.Clear()
                Response.ContentType = "application/pdf"
                Response.BinaryWrite(myFileArray)
                Response.End()

            Case "Word"
                Dim myFileArray As Byte()
                Dim myReport As Word = CType(myFile, Word)
                Dim wordObject As System.Object = myReport.ByteStream
                myFileArray = CType(wordObject, Byte())

                Response.Clear()
                Response.ContentType = "application/msword"
                Response.BinaryWrite(myFileArray)
                Response.End()

            Case "Rtf"
                Dim myFileArray As Byte()
                Dim myReport As Rtf = CType(myFile, Rtf)
                Dim rtfObject As System.Object = myReport.ByteStream
                myFileArray = CType(rtfObject, Byte())

                Response.Clear()
                Response.ContentType = "application/msword"
                Response.BinaryWrite(myFileArray)
                Response.End()

            Case "Excel"
                Dim myFileArray As Byte()
                Dim myReport As Excel = CType(myFile, Excel)
                Dim excelObject As System.Object = myReport.ByteStream
                myFileArray = CType(excelObject, Byte())

                Response.Clear()
                Response.ContentType = "application/vnd.ms-excel"
                Response.BinaryWrite(myFileArray)
                Response.End()

            Case Else
                Response.Clear()
                Response.Write("Could not open Report")
                Response.End()

        End Select

        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        viewListing.NavigateUrl = "Default.aspx?folderID=" & folderID
    End Sub
End Class

myCrystalReportViewer.ReportSource = Utilities.RetrieveReportSource(myInfoStore, reportID) above calls my utilities.vb class
Code:
    ' <summary>
    ' In this method, a Report instance is retrieved from the InfoStore variable.
    ' </summary>
    ' <param name="enterpriseSession">Manages the CrystalEnterprise session.</param>
    ' <param name="reportID">The id matching the corresponding report source.</param>
    ' <returns>The ISCRReportSource interface containing the report source.</returns>
    Public Shared Function RetrieveReportSource(ByVal myInfoStore As InfoStore, _
                                        ByVal reportID As String)
        Dim query As String = "Select * from CI_INFOOBJECTS where SI_ID=" + reportID
        Dim myInfoObjects As InfoObjects = myInfoStore.Query(query)
        Dim myInfoObject As InfoObject = myInfoObjects(1)

        Select Case myInfoObject.GetType.Name
            Case "Report"
                Dim myReport As Report = CType(myInfoObject, Report)
                Return myReport
            Case "Pdf"
                Dim myReport As Pdf = CType(myInfoObject, Pdf)
                Return myReport
            Case "Rtf"
                Dim myReport As Rtf = CType(myInfoObject, Rtf)
                Return myReport
            Case "Word"
                Dim myReport As Word = CType(myInfoObject, Word)
                Return myReport
            Case "Excel"
                Dim myReport As Excel = CType(myInfoObject, Excel)
                Return myReport
        End Select

    End Function

Any help, or direction would be greatly appreciated.

The bad thing about this is that I had this all figured out at an old job, but some how I managed to lose all that code! aarrg!!

Kind regards,
Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top