Although ActiveReports 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.
Use the SaveLayout method to save your report layout at run time.
The following example shows what the code for the method looks like.
To 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() |
To 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.
The following examples show what the code for the method looks like.
To 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() |
To 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(); |