Storing and loading a report
You may store a report in the following ways:
In a web form:
Typical scenario that we have looked at before, uses this method. The report is stored in the ReportResourceString
property of the WebReport component. This method has the following pros and cons:
+ it's a simplest way to work with FastReport .NET;
- the report template is stored in the ViewState of your web form. It will be transferred on a client side. It may slow down the work if the report has a big size;
- this method is not compatible with "Medium Trust" mode.
The report loading is performed automatically.
In the .FRX file:
This method assumes that the report is stored in a file in a special folder "App_Data". To do this:
- run the report designer;
- create a report and save it to the .FRX file;
- in the Solution Explorer, select the "App_Data" folder, right-click it and choose the "Add|Existing Item..." item. Select the report file that you just saved;
- select the WebReport component and clear its ReportResourceString
property;
- select the ReportFile
property, invoke its editor and choose the report from "App_Data" folder.
This method has the following pros and cons:
+ the report is not transferred to a client machine;
- this method is not compatible with "Medium Trust" mode.
The report loading is performed automatically.
A report can also be loaded from WebReport.StartReport
event handler. Example code in StartReport
:
(sender as WebReport).Report.Load(this.Server.MapPath("~/App_Data/report.frx"));
As a C#/VB.NET class:
In this method, you work with the report as a class. To do this:
- design your report and save in to the .cs/.vb file. To do this, select "file type" in the "Save" dialog. The file type maybe either .cs or .vb - it depends on the script language in the report (it may be changed in the "Report/Options..." menu);
- include that file into your project. It's better to save it in the "App_Code" folder;
- clear both ReportResourceString
and ReportFile
properties of the WebReport component.
This method has the following pros and cons:
+ you can work with the report as a regular class;
+ you can debug the report in the Visual Studio;
+ it's the only way to use a report in the "Medium Trust" mode;
- you cannot edit such a report. To do this, you need the original .FRX file.
To work with a report, create the WebReport.StartReport
event handler. In this handler, you should do the following:
- create an instance of your report class;
- register the data;
- set the report to the Report
property of the WebReport component.
Example of the StartReport
event handler:
SimpleListReport report = new SimpleListReport();
report.RegisterDataAsp(your_data, "your_data_name");
WebReport1.Report = report;
The prepared report can be displayed from WebReport.StartReport
event handler using the property WebReport.ReportDone
. Example code in StartReport
to load and display a prepared report:
(sender as WebReport).Report.LoadPrepared(this.Server.MapPath("~/App_Data/Prepared.fpx"));
(sender as WebReport).ReportDone = true;