C #: How to load internal .html file resource into webbrowser control?

I got a file called test.html, which is just a basic html file with some text in it. Test.html is a resource in my C # project, and I got a web browser called webbrowser1 that should load my html file.

So how to load test.html into your web browser

I tried this, but it does not work:

private void button1_Click(object sender, EventArgs e)
{
     webBrowser1.DocumentStream = 
         Properties.Resources.ResourceManager.GetStream("test.html");
}

Any solutions please?

+4
source share
1 answer

I think "test.html" is not a valid name for the resource. Instead, try using "test_html". Then the following works very well.

private void button1_Click(object sender, EventArgs e)
{
     string html = Properties.Resources.test_html;
     webBrowser1.DocumentText = html;
}

So if the HTML file

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8" />
  <title></title>
</head>
<body>
  This is some resource HTML
</body>
</html>

enter image description here

+8

All Articles