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
- While in the design view of an ActiveReport, select Save Layout from the Report menu.
- Name the file appropriately and select the location in which to save it.
- 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
- While in an ActiveReport, click Report > Load Layout.
- Select the RPX file from the appropriate location.
- 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#
- Right-click on the Windows Form and select View Code from the shortcut menu to see the code view for the Windows form. Add the following code to save the report.
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#
- Right-click on the Windows Form to see the code view for the Windows form. Add the following code to load a report.
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.