Binding to a File Directory Path in Code
Object Model
This report binding scenario uses the CrystalReportViewer (see Report Binding with CrystalReportViewer Object Model.)
Location of Reports
Reports are in a file directory.
Description
This is the simplest report binding scenario: you bind a report in the file directory by its path string to the CrystalReportViewer control.
Pros
- Low maintenance: reports can be added, removed or modified without recompiling your application.
- Simplified implementation: no need to declare and instantiate classes. It bypasses the use of the ReportDocument object model, by passing a report directly to the CrystalReportViewer control.
Cons
- Limited distribution: reports typically stay on the same machine as the application, due to the complications involved when permissions are granted to the ASPNET user account to access another machine on the network.
- Limited object model: this binding scenario offers only the limited object model that is part of the CrystalReportViewer. See Which Object Model Should I Use?.
Implementation
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.
Within the ConfigureCrystalReports() method (that you have created in Project Setup), assign a file directory path string to the ReportSource property of CrystalReportViewer class.
This binds the report directly to the control. All programmatic interaction with the report must be done within the limited CrystalReportViewer object model.
myCrystalReportViewer.ReportSource = _ "C:\Program Files\Microsoft Visual Studio 9.0\" _ & "Crystal Reports\Samples\En\Reports\General Business\" _ & "World Sales Report.rpt"
crystalReportViewer.ReportSource = "C:\\Program Files\\Microsoft Visual Studio 9.0\\" + "Crystal Reports\\Samples\\En\\Reports\\General Business\\" + "World Sales Report.rpt";
Note
The file directory path points to the sample reports in Visual Studio. For the full path to the sample reports in your version of Crystal Reports, see Sample Reports' Directory.