To instantiate the FunctionTest report as a non-embedded report and bind it to the CrystalReportViewer control

In Project Setup, you placed a CrystalReportViewer control on the Web or Windows Form. In the previous step, you have added a FunctionTest report to the project.

In this section, you instantiate the FunctionTest report as a non-embedded report and bind it to the CrystalReportViewer control.

  1. Open the Web or Windows Form.

  2. From the View menu, click Code.

  3. Add a new class-level declaration for the ReportDocument report wrapper class, using the variable name functionTestReport. Set its access modifier to private.

> [!NOTE]
> <P>The ReportDocument class is a member of the CrystalDecisions.CrystalReports.Engine namespace. You have added an "Imports" [Visual Basic] or "using" [C#] declaration for this namespace in <A href="ms227453(v=vs.90).md">Project Setup</A>. When you instantiate ReportDocument and load a report into the namespace, you gain access to the report through the SDK, without embedding the report.</P>


``` vb
Private functionTestReport As ReportDocument
```

``` csharp
private ReportDocument functionTestReport;
```
  1. Within the ConfigureCrystalReports() method (that you have created in Project Setup), instantiate the ReportDocument class.
``` vb
functionTestReport = New ReportDocument()
```

``` csharp
functionTestReport = new ReportDocument();
```
  1. In the next line, call the Load() method of the ReportDocument instance and paste into it the report file name.
> [!NOTE]
> <P>Wrap the report file name in a Server.MapPath() method. This will automatically generate the file directory path to the report based on the report name.</P>


``` vb
functionTestReport.Load(Server.MapPath("FunctionTest.rpt"))
```

``` csharp
functionTestReport.Load(Server.MapPath("FunctionTest.rpt"));
```
  1. On the next line, beneath the report loading, bind the ReportSource property of the CrystalReportViewer to the ReportDocument instance.

    myCrystalReportViewer.ReportSource = functionTestReport
    
    crystalReportViewer.ReportSource = functionTestReport;
    

    You are now ready to build and run your project.

  2. From the Debug menu, click Start.

The report displays, with the new field calculating an exchange rate for last year's sales, based upon the User Function Library that you created.
  1. Return to Visual Studio and click Stop to exit from debug mode.