ActiveReports 18 .NET Edition
Developers / Work with Reports using Code / Section Report / Create a Report or Load an Existing Report
In This Topic
    Create a Report or Load an Existing Report
    In This Topic

    This topic discusses about creating and loading a Section Report (xml or code based) in designer using code. We recommend you to create a new report directly from the standalone designer or you using the built-in project templates from Visual Studio.

    Create a Report

    Use NewReport() method in the Designer class to initialize the designer with a new report layout, with specified type. Make sure to add MESCIUS.ActiveReports.Design.Win package to your project.

    C#. Add using statements on the top of Form.cs
    Copy Code
    using System.Windows.Forms;
    using GrapeCity.ActiveReports.Design;
    
    C# code. Paste INSIDE the Form Load event
    Copy Code
    var _designer = new Designer() { Dock = DockStyle.Fill };
    _designer.NewReport(DesignerReportType.Section);
    Controls.Add(_designer);
    

    Load an RPX file at Design Time

    1. From the Visual Studio > Report menu, select Load Layout.
      Note: The Report menu in Visual Studio 2019 and above is available as submenu under Extensions. You should select the Design View of the report in the ActiveReports Designer first.
    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.

    Load an RPX file into the ActiveReports Viewer at Run Time

    Use the LoadLayout(XmlReader) method to load your report layout at run time.

    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.

      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()
      
      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 + "\\report.rpx");
      rpt.LoadLayout(xtr);
      xtr.Close();
      viewer1.Document = rpt.Document;
      rpt.Run();
      

     

    See Also