ActiveReports 6 Online Help
Load a File into a RichText Control
See Also Send comments on this topic.
ActiveReports 6 > ActiveReports User Guide > How To > Load a File into a RichText Control

Glossary Item Box

You can load an RTF file or an HTML file into the ActiveReports RichText control at run time.

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 in use by that first iteration and returns "file in use" errors when the section is processed again.

To write an RTF file to load into a RichText control

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

    ShowPaste 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
    Month Sales
    October $4,872
    November $8,517
    December $9,623
  2. Save the file as sample.rtf in the debug directory in the bin folder of your project.

To load the RTF file into the RichText control

  1. Double-click the detail section of the report to create an event-handling method for the Detail Format event.
  2. Add code to the handler to load the RTF file into the RichText control.
Note: The Application.Startup path code does not work in preview mode. You must run the project in order to see the file load.

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 Detail 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)

ShowTo 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);

To write a quick HTML file to load into a RichText control

  1. Open Notepad and paste the following code into it.

    ShowHTML code

    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>
    <table>
    <tr><th>Month</th><th>Sales</th></tr>
    <tr><td>October</td><td>$4,872</td></tr>
    <tr><td>November</td><td>$8,517</td></tr>
    <tr><td>December</td><td>$9,623</td></tr>
    </table>
    </body>
    </html>
    
  2. Save the file as sample.html in the debug directory in the bin folder of your project.

Loading the HTML file into a RichText control

  1. Double-click the detail section of the report to create an event-handling method for the Detail Format event.
  2. Add code to the handler to load the HTML file into the RichText control.
Note: The Application.Startup path code does not work in preview mode. You must run the project in order to see the file load.

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 Detail 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)

ShowTo 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.RextTextBox1.Load(streamHTML, RichTextType.Html);

See Also

Walkthroughs
Mail Merge with RichText

Concepts
RichText