ActiveReports 18 .NET Edition
Developers / Working with Reports / Section Report / Code-based Section reports / Load an RTF or HTML File in RichTextBox at Runtime
In This Topic
    Load an RTF or HTML File in RichTextBox at Runtime
    In This Topic

    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 at run-time.

    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.

    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.

     

    Write an RTF file to load into a RichTextBox control

    1. Open WordPad, and paste a formatted text into it, for example:

      [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.
    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.

    Load an RTF file into a RichTextBox control

    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.

      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)
      

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

    Write an HTML file to load into a RichTextBox control

    1. Open a Notepad, and paste an HTML code into it, for example:
      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>Brazi1>
      <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.

    Load an HTML file into the RichTextBox control

    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.

      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)
      

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

     

    See Also