ActiveReports 12
Load a File into a RichTextBox Control
ActiveReports 12 > ActiveReports User Guide > How To > Section Report How To > Work with Report Controls > Load a File into a RichTextBox Control

In a section layout, you can load an RTF or an HTML file into the RichTextBox control both at design time and at run time . Following is a step-by-step process that helps you load these files into the RichTextBox control.

These steps assume that you have already added a Section Report (code based) template in a Visual Studio project and have placed a RichTextBox control inside its detail section. See Adding an ActiveReport to a Project for more information.

Caution: Do not attempt to load a file into a RichTextBox in a section that repeats. After the first iteration of the section, the RTF or HTML file is already in use by that first iteration and returns "file in use" errors when that section is processed again.

To write an RTF file to load into a RichTextBox control

  1. Open wordpad, and paste the following formatted text into it.

    Paste the following section into an RTF File.

    Customer List by Country

    Argentina

    • Rancho grande
    • Océano Atlántico Ltda.
    • Cactus Comidas para llevar

    Austria

    • Piccolo und mehr
    • Ernst Handel

    Belgium

    • Suprêmes délices
    • Maison Dewey

    Brazil

    • Familia Arquibaldo
    • Wellington Improtadora
    • Que Delícia
    • Tradição Hipermercados
    • Ricardo Adocicados
    • Hanari Carnes
    • Queen Cozinha
    • Comércio Mineiro
    • Gourmet Lanchonetes
  2. Save the file as sample.rtf in the debug directory inside the bin folder of your project.
Note: The RichTextBox control is limited in its support for advanced RTF features such as the ones supported by Microsoft Word. In general, the features supported by WordPad are supported in this control.

To load an RTF file into the RichTextBox control at design time

  1. On the report design surface, add a RichTextBox control.
  2. With the RichTextBox control selected, at the botton of the Properties Window, click the Load File command. See Properties Window for a description of commands. 
  3. In the Open dialog that appears, browse to an *.RTF file (For example, sample.rtf) and click the Open button to load the file in the RichTextBox control.

To load an RTF file into the RichTextBox control at run time

Note: The RichTextBox control has limited support for advanced RTF features such as the ones supported by Microsoft Word. Therefore, use a WordPad for obtaining best results.

These steps assume that the RTF file (for example, sample.rtf) to load has been saved in the bin/debug directory of your project.

  1. Right-click the report and select View Code to open the code view.
  2. Add an Imports (Visual Basic.NET) or using (C#) statement at the top of the code view for the GrapeCity.ActiveReports.SectionReportModel namespace.
  3. In the design view, double-click the detail section of the report to create an event-handling method for the Detail Format event.
  4. Add the following code to the handler to load the RTF file into the RichTextBox control.

    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 Detail1_Format event.
    Copy Code
    Dim streamRTF As New System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\sample.rtf", System.IO.FileMode.Open)
    Me.RichTextBox1.Load(streamRTF, RichTextType.Rtf)

    To write the code in C#

    C# code. Paste INSIDE the detail_Format event.
    Copy Code

    System.IO.FileStream streamRTF = new System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\\sample.rtf", System.IO.FileMode.Open);
    this.richTextBox1.Load(streamRTF, RichTextType.Rtf);

    Note: The Application.Startup path code does not work in preview mode. You must run the project in order to see the file load.

To write an HTML file to load into a RichTextBox control

  1. Open a Notepad, and paste the following HTML code into it.
    HTML code. Paste in a NotePad file.
    Copy Code
    <html>
    <body>
    <center><h1>Customer List by Country</h1></center>
    <h1>Argentina</h1>
    <ul>
    <li>Rancho grande
    <li>Océano Atlántico Ltda.
    <li>Cactus Comidas para llevar
    </ul>
    <h1>Austria</h1>
    <ul>
    <li>Piccolo und mehr
    <li>Ernst Handel
    </ul>
    <h1>Belgium</h1>
    <ul>
    <li>Suprêmes délices
    <li>Maison Dewey
    </ul>
    <h1>Brazil</h1>
    <ul>
    <li>Familia Arquibaldo
    <li>Wellington Improtadora
    <li>Que Delícia
    <li>Tradição Hipermercados
    <li>Ricardo Adocicados
    <li>Hanari Carnes
    <li>Queen Cozinha
    <li>Comércio Mineiro
    <li>Gourmet Lanchonetes
    </ul>
    </body>
    </html>
    
  2. Save the file as sample.html.

To load an HTML file into the RichTextBox control at design time

  1. On the report design surface, add a RichTextBox control.
  2. With the RichTextBox control selected, at the bottom of the Properties Window, click the Load File command. See Properties Window for a description of commands.
  3. In the Open dialog that appears, browse to an *.html file (For example, sample.html) and click the Open button to load the file in the RichTextBox control.

To load an HTML file into a RichTextBox control at run time

These steps assume that the HTML file (for example, sample.html) to load has been saved in the bin/debug directory of your project.

  1. Right-click the report and select View Code to open the code view.
  2. Add an Imports (Visual Basic.NET) or using (C#) statement at the top of the code view for the GrapeCity.ActiveReports.SectionReportModel namespace.
  3. In the design view, double-click the detail section of the report to create an event-handling method for the Detail Format event.
  4. Add code to the handler to load the HTML file into the RichText control.

    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 Detail1_Format event.
    Copy Code
    Dim streamHTML As New System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\sample.HTML", System.IO.FileMode.Open)
    Me.RichTextBox1.Load(streamHTML, RichTextType.Html)

    To write the code in C#

    C# code. Paste INSIDE the detail_Format event.
    Copy Code
    System.IO.FileStream streamHTML = new System.IO.FileStream(System.Windows.Forms.Application.StartupPath + "\\sample.html", System.IO.FileMode.Open);
    this.richTextBox1.Load(streamHTML, RichTextType.Html);
    Note: The Application.Startup path code does not work in preview mode. You must run the project in order to see the file load.
See Also

Concepts