ActiveReports for .NET 3 Online Help Request technical support
Saving and Loading RPX Files
See Also
User Guide > How-To Section > Saving and Loading RPX Files

Glossary Item Box

Although ActiveReports for .NET 3.0 writes report layouts in either C# or VB.NET, you can choose to save your the layout of your report as an RPX (report XML) file for portability and editing. If you make changes to the RPX and bring the report back into the Visual Studio IDE, ActiveReports will reflect the changes in C# or VB.NET.
When an RPX-based layout is loaded into a project it will supersede the currently active report. Thus, in order to avoid replacing any important layouts in the current project, a new blank ActiveReport must be created before loading the file. After you have created the new ActiveReport, load the RPX file into it.

To save a current report as an RPX file

  1. While in the design view of an ActiveReport, select Save Layout from the Report menu.
  2. Name the file appropriately and select the location in which to save it.
  3. Click Save to save the selected report layout.
    Datasets are not able to be saved in the component tray, but can be easily regenerated from the data adapter, which is saved.

To load an existing RPX file

  1. While in an ActiveReport, click Report > Load Layout.
  2. Select the RPX file from the appropriate location.
  3. Click Open to load the selected report layout.

To write the code to save a report as an RPX file in Visual Basic or C#

The following example shows what the code for the method looks like.

'Visual Basic
Dim rpt As New ActiveReport1()
Private Sub SaveRPX()
   rpt.Run()
   rpt.SaveLayout("C:\NewRPX.RPX")
End Sub

//C#
private void SaveRPX()
{
   NewActiveReport1 rpt = new ActiveReport1();
   rpt.Run();
   rpt.SaveLayout(@"C:\NewRPX.RPX");
}
The SaveLayout method uses utf-16 encoding when you save to a stream, and utf-8 encoding when you save to a file.

To write the code to load the saved RPX into the ActiveReports viewer in Visual Basic or C#

The following example shows what the code for the method looks like.

'Visual Basic
Dim rpt As New ActiveReport1()
Private Sub LoadRPX()
   rpt.LoadLayout("C:\NewRPX.RPX")
   Viewer1.Document = rpt.Document
   rpt.Run()
End Sub

//C#
private void LoadRPX()
{
   NewActiveReport1 rpt = new ActiveReport1();
   rpt.LoadLayout(@"C:\NewRPX.rpx");
   viewer1.Document = rpt.Document;
   rpt.Run();
}
When saving to an RPX file, be sure to save the report before it runs. Saving the layout after the report runs will cause any dynamic changes made to properties or sections to be saved in the layout. When calling SaveLayout inside the report's code, use the ReportStart event. Also note that when saving a report layout, only the code in the script editor will be saved to the file. Any code behind the report in the .cs or .vb file will not be saved to the RPX file.

Notes About Datasets and Component Trays

When saving a layout that contains a dataset, the data adapter and data connection are saved in the component tray, but the dataset itself is lost. When the saved layout is loaded into another report, you must generate the dataset again, as there is no convenient way to reconnect the old dataset.

 

See Also

©2009. All Rights Reserved.