title: How to feed WebBrowser control and manipulate the HTML document?
body: <p>Good day</p>
  
  <p>I have question about displaying html documents in a windows forms applications. App that I'm working on should display information from the </p>
  
  <p>database in the html format. I will try to describe actions that I have taken (and which failed):</p>
  
  <p>1) I tried to load "virtual" html page that exists only in memory and dynamically change it's parameters (webbMain is a WebBrowser control):</p>
  
  <pre><code>public static string CreateBookHtml()
  {
   StringBuilder sb = new StringBuilder();
  
   //Declaration
   sb.AppendLine(@"&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;");
   sb.AppendLine(@"&lt;?xml-stylesheet type=""text/css"" href=""style.css""?&gt;");
   sb.AppendLine(@"&lt;!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.1//EN"" 
                      ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd""&gt;");
   sb.AppendLine(@"&lt;html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en""&gt;"); 
  
   //Head
   sb.AppendLine(@"&lt;head&gt;");
   sb.AppendLine(@"&lt;title&gt;Exemplary document&lt;/title&gt;");
   sb.AppendLine(@"&lt;meta http-equiv=""Content-Type"" content=""application/xhtml+xml; 
                                                                  charset=utf-8""/   &gt;");
   sb.AppendLine(@"&lt;/head&gt;");
  
   //Body
   sb.AppendLine(@"&lt;body&gt;");
   sb.AppendLine(@"&lt;p id=""paragraph""&gt;Example.&lt;/p&gt;");
   sb.AppendLine(@"&lt;/body&gt;");
   sb.AppendLine(@"&lt;/html&gt;");
  
   return sb.ToString();
  }
  </code></pre>
  
  <p>void LoadBrowser()
      {
      this.webbMain.Navigate("about:blank");
      this.webbMain.DocumentText = CreateBookHtml();
      HtmlDocument doc = this.webbMain.Document;
      }</p>
  
  <p>This failed, because doc.Body is null, and doc.getElementById("paragraph") returns null too. So I cannot change paragraph InnerText property. </p>
  
  <p>Furthermore, this.webbMain.DocumentText is "\0"... </p>
  
  <p>2) I tried to create html file in specified folder, load it to the WebBrowser and then change its parameters. Html is the same as created by </p>
  
  <p>CreateBookHtml() method:</p>
  
  <pre><code>private void LoadBrowser()
          {
              this.webbMain.Navigate("HTML\\BookPage.html"));             
              HtmlDocument doc = this.webbMain.Document;
          }
  </code></pre>
  
  <p>This time this.webbMain.DocumentText contains Html data read from the file, but doc.Body returns null again, and I still cannot take element using </p>
  
  <p>getByElementId() method. Of course, when I have text, I would try regex to get specified fields, or maybe do other tricks to achieve a goal, but I wonder - is there simply way to mainipulate html? For me, ideal way would be to create HTML text in memory, load it into the WebBrowser control, and then dynamically change its parameters using IDs. Is it possible? Thanks for the answers in advance, best regards,</p>
  
  <p>Paweł</p>