ActiveReports Developer 7
Save and Load RPX Report Files
See Also Support Forum
ActiveReports Developer 7 > ActiveReports Developer Guide > How To > Section Report How To > Save and Load RPX Report Files

Glossary Item Box

Although ActiveReports Developer writes report layouts in either C# or Visual Basic.NET, you can save the layout of your report as a report XML (RPX) file for portability. If you make changes to the RPX file and load it back into an ActiveReport in Visual Studio, you can see the changes you made reflected in the C# or Visual Basic.NET code in the YourReportName.Designer.vb or YourReportName.Designer.cs file.

Caution: When you load an RPX layout into a report object, it overwrites everything in the report object. In order to avoid overwriting important layouts, add a new blank ActiveReport and load the RPX file onto it.

ShowTo save a report as an RPX file at design time

  1. From the Visual Studio Report menu, select Save Layout.
  2. In the Save As dialog that appears, set the file name and select the location where you want to save it. The file extension is *.rpx.
  3. Click the Save button to save the report layout and close the dialog.
Note: When you save a layout that contains a dataset, ActiveReports saves the data adapter and data connection in the component tray, but not the dataset itself. When the saved layout is loaded into another report, you can regenerate the dataset with the data adapter and data connection.

ShowTo load an RPX file at design time

  1. From the Visual Studio Report menu, select Load Layout.
  2. In the Open dialog that appears, navigate to the location of the .rpx file and select it.
  3. Click the Open button to load the report layout.

ShowTo save a report as an RPX file at runtime

Use the SaveLayout method to save your report layout at runtime.

Note: When you save a report layout, ActiveReports Developer only saves the code in the script editor to the file. Any code behind the report in the .cs or .vb file is not saved to the RPX file.
  1. Right-click the Windows Form and select View Code to see the code view for the Windows form.
  2. Add the following code to the Form class to save the report.

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

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Form class. Copy Code
Dim rpt As New SectionReport1()
Dim xtw As New System.Xml.XmlTextWriter(Application.StartupPath + "\report.rpx", Nothing)
rpt.SaveLayout(xtw)
xtw.Close()

ShowTo write the code in C#

C# code. Paste INSIDE the Form class. Copy Code
SectionReport1 rpt = new SectionReport1();
System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(Application.StartupPath + "\\report.rpx", null);
rpt.SaveLayout(xtw);
xtw.Close();

Save report layouts before they run. If you save a layout after the report runs, you also save any dynamic changes made to properties or sections in the report. To avoid this when you call SaveLayout inside the report code, use the ReportStart event.

Note: The SaveLayout method uses utf-16 encoding when you save to a stream, and utf-8 encoding when you save to a file.

ShowTo load an RPX file into the ActiveReports viewer at runtime

  1. Right-click on the Windows Form and select View Code to see the code view for the Windows form.
  2. Add the following code to the form class to load a report.

The following examples show what the code for the method looks like.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Form class. Copy Code
Dim rpt As New GrapeCity.ActiveReports.SectionReport()
' For the code to work, this report.rpx must be stored in the bin\debug folder of your project.
Dim xtr As New System.Xml.XmlTextReader(Application.StartupPath + "\report.rpx")
rpt.LoadLayout(xtr)
xtr.Close()
Viewer1.Document = rpt.Document
rpt.Run()

ShowTo write the code in C#

C# code. Paste INSIDE the Form class. Copy Code
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
// For the code to work, this report.rpx must be stored in the bin\debug folder of your project.
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Application.StartupPath + "\\Sample.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
viewer1.Document = rpt.Document;
rpt.Run();

See Also

©2014. ComponentOne, a division of GrapeCity. All rights reserved.