Share via


Binding to InfoObject Cast as Report

Note

This page describes functionality that is not available in Crystal Reports for Visual Studio, but is available in one of the upgraded versions. For more information about Crystal Reports for Visual Studio, see What is Crystal Reports for Visual Studio? For more information about upgraded versions, see Upgrade Options.

Object Model

This report binding scenario uses InfoObject (see Report Binding with InfoObject Object Model (BOE)).

Location of Reports

Stored on a server in Crystal Reports Server or BusinessObjects Enterprise.

Description

The InfoObject object model is supplied with Crystal Reports Server or BusinessObjects Enterprise. It treats all Enterprise items in the system (reports, users, groups, servers, server groups, folders) as information objects that can be interacted with programmatically. All information objects in the object model are represented by corresponding classes of the same name. These classes inherit from InfoObject.

To bind reports using this object model, you retrieve a report from Crystal Reports Server or BusinessObjects Enterprise that is wrapped as an InfoObject instance. To bind to this InfoObject instance, assign the ReportSource property of the CrystalReportViewer control to the InfoObject instance.

Pros

  • Useful for scheduling reports to run at certain times, with specific parameters, to be output to FTP, SMTP, disk or printer destinations.

Cons

To bind to a report that is wrapped as an InfoObject and cast to Report

  • Crystal Reports Server or BusinessObjects Enterprise must be installed and verified to be working.

  • Crystal Reports Server or BusinessObjects Enterprise SDK (including the .NET assemblies) must be installed on your development machine.

    Note

    If you have installed Crystal Reports Server or BusinessObjects Enterprise on your development machine, the SDK is included with that installation.

  • Locate and write down the name of a Crystal Reports Server or BusinessObjects Enterprise server. For purposes of this example, the server name is "BOE01".

Note

This procedure works only with a project that has been created from Project Setup. Project Setup contains specific namespace references and code configuration that is required for this procedure, and you will be unable to complete the procedure without that configuration. Therefore, before you begin this procedure, you must first follow the steps in Project Setup.

  1. Use the Publishing Wizard to publish the Chart.rpt to the Crystal Reports Server or BusinessObjects Enterprise server.
> [!NOTE]
> <P>To learn how to use the Publishing Wizard, see the Crystal Reports Server or BusinessObjects Enterprise User documentation.</P>
> <P>For information about sample reports, see <A href="ms225622(v=vs.90).md">Sample Reports' Directory</A>.</P>
  1. Add the following assembly references to your project:

    • CrystalDecisions.Enterprise.Framework
    • CrystalDecisions.Enterprise.InfoStore
    • CrystalDecisions.Enterprise.Desktop.Report
  2. At the top of the code-behind page, add a "Imports" [Visual Basic] or "using" [C#] statement for the CrystalDecisions.Enterprise namespace and the CrystalDecisions.Enterprise.Desktop namespace.

``` vb
Imports CrystalDecisions.Enterprise
Imports CrystalDecisions.Enterprise.Desktop
```

``` csharp
using CrystalDecisions.Enterprise;
using CrystalDecisions.Enterprise.Desktop;
```

You are now ready to add code that binds to an InfoObject instance containing a report from Crystal Reports Server or BusinessObjects Enterprise.
  1. Within the ConfigureCrystalReports() method (that you have created in Project Setup), declare a serverName string and set it to the name of the Crystal Reports Server or BusinessObjects Enterprise server.

    Dim serverName As String = "BOE01"
    
    string serverName = "BOE01";
    
  2. Declare and instantiate the SessionMgr class.

    Dim mySessionMgr As SessionMgr = New SessionMgr()
    
    SessionMgr sessionMgr = new SessionMgr();
    
  3. Pass the user name (Administrator), the password (blank), the serverName variable, and the logon type (secEnterprise) to the Logon method of the SessionMgr instance and retrieve it as an instance of EnterpriseSession.

    Dim myEnterpriseSession As EnterpriseSession = mySessionMgr.Logon(
    _
            "Administrator", "", serverName, "secEnterprise")
    
    EnterpriseSession enterpriseSession = sessionMgr.Logon(
          "Administrator", "", serverName, "secEnterprise");
    
  4. Retrieve the InfoStore service (as EnterpriseService) from the GetService method of EnterpriseSession.

    Dim myEnterpriseService As EnterpriseService = _
            myEnterpriseSession.GetService("InfoStore")
    
    EnterpriseService enterpriseService =
    enterpriseSession.GetService("InfoStore");
    
  5. Declare and instantiate InfoStore, by using the retrieved InfoStore service.

    Dim myInfoStore As InfoStore = New InfoStore(myEnterpriseService)
    
    InfoStore infoStore = new InfoStore(enterpriseService);
    
  6. Enter the query string below to query Crystal Reports Server or BusinessObjects Enterprise for the report.

    Dim queryString As String = "Select SI_ID, SI_NAME, SI_PARENTID
    From CI_INFOOBJECTS " _
                    & "Where SI_PROGID='CrystalEnterprise.Report' "
    _
                    & "And SI_NAME Like 'Chart'"
    
    string queryString = "Select SI_ID, SI_NAME, SI_PARENTID From
    CI_INFOOBJECTS "
       + "Where SI_PROGID='CrystalEnterprise.Report' "
       + "And SI_NAME Like 'Chart'";
    
  7. Retrieve an InfoObjects indexed class that contains the query result, by passing the query string to the Query method of InfoStore.

    Dim myInfoObjects As InfoObjects = myInfoStore.Query(queryString)
    
    InfoObjects infoObjects = infoStore.Query(queryString);
    
  8. Retrieve the InfoObject from the first column of the InfoObjects indexed class.

> [!NOTE]
> <P>The InfoObjects indexed class is 1-based, not 0-based.</P>


``` vb
Dim myInfoObject As InfoObject = myInfoObjects(1)
```

``` csharp
InfoObject infoObject = infoObjects[1];
```
  1. Declare a Report instance and cast the InfoObject to Report.

    Dim myReport As Report = CType(myInfoObject, Report)
    
    Report report = (Report)infoObject;
    
  2. Set the EnterpriseLogon property of the CrystalReportViewer control to the EnterpriseSession instance.

    myCrystalReportViewer.EnterpriseLogon = myEnterpriseSession
    
    crystalReportViewer.EnterpriseLogon = enterpriseSession;
    
  3. Bind the Report instance to the CrystalReportViewer control.

    myCrystalReportViewer.ReportSource = myReport
    
    crystalReportViewer.ReportSource = report;
    

See Also