To load HTML content from a string use Browser.LoadHTML() method. For example:

browser.LoadHTML("<html><body><h1>Load HTML Sample</h1></body></html>");


The output will look like this:

Example

C#

using System;
using DotNetBrowser;

namespace MyNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create Browser instance.
            Browser browser = BrowserFactory.Create();

            // Load HTML content from string .
            browser.LoadHTML("<html><body><h1>Load HTML Sample</h1></body></html>");
            
            // Dispose Browser instance.
            browser.Dispose();
        }
    }
}

VB.NET

Imports DotNetBrowser

Module Module1
    Sub Main(args As String())
        ' Create Browser instance.
        Dim browser As Browser = BrowserFactory.Create()
        ' Load HTML content from string.
        browser.LoadHTML("<html><body><h1>Load HTML Sample</h1></body></html>")
        ' Dispose Browser instance.
        browser.Dispose()
    End Sub
End Module


Note: there are a couple of recommendations related to loading file resources (e.g. .js or .css files) from the file system in your HTML:

  • you should specify several Chromium switches to allow loading these resources in Chromium: BrowserPreferences.SetChromiumSwitches(“--disable-web-security”, “--allow-file-access-from-files”); 
  • you should specify the absolute paths to file resources

Example

C#

string fullPath = Path.GetFullPath("MainForm.css");
const string s1 = "\"stylesheet\"";
string s2 = fullPath;

browser.LoadHTML(@"<html>
                  <head><link rel={s1} href='{s2}'/></head>
                  <body><h1>Load HTML Sample</h1></body>
                  </html>");

VB.NET

Dim fullPath As String = Path.GetFullPath("MainForm.css")
Const s1 As String = """stylesheet"""
Dim s2 As String = fullPath

browser.LoadHTML("<html>
          <head><link rel={s1} href='{s2}'/></head>
          <body><h1>Load HTML Sample</h1></body>
          </html>")