ActiveReports 8 > 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
Paste into an RTF File
Customer List by Country
Argentina
Austria
Belgium
Brazil
![]() |
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
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.
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) |
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); |
![]() |
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
HTML 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> </body> </html> |
To load an HTML file into the RichTextBox control at design time
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.
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) |
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. |