Reputation: 61
I got the file named test.html which is just a basic html file with some text in it. The test.html is a resource in my c# project, and I got a webbrowser named webbrowser1 that needs to load my html file.
So how to load the test.html into my webbrowser
I tried this, but it doesn't work:
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.DocumentStream =
Properties.Resources.ResourceManager.GetStream("test.html");
}
Any solutions please?
Upvotes: 6
Views: 12112
Reputation: 19
Here is my solution for this problem. I needed a way to make a reusable quick popup help, besides making several external html files to launch.
I added the html files into the project resource.
I will use the Capacities.html
file as my example.
<!DOCTYPE html>
<html lang="en">
<style>
#mainHelp {
width:500px;
margin:0 auto;
}
</style>
<div id="mainHelp">
If desired, "Fluid Capacities" can be set for each fluid (Water, Oil, Fuel) and side (Port, Stbd).
If capacities are set to '0', this disables reporting of the capacities. The capacities are whole number values,
but can be entered as either liters or gallons.
</div>
</html>
In my QuickHelpView.xaml.cs
, to make the window reusable, I send a string of the caller to direct to the resource needed. In this case, the "capacity"
was needed.
public void SetupQuickHelp(string _helpSelected)//, FileDataAccess aFilePathAccess
{
//filePathAccess = aFilePathAccess;
string htmlText = "";
if (_helpSelected == "instance")
{
htmlText = Properties.Resources.InstanceSettings;
}
else if (_helpSelected == "engine")
{
htmlText = Properties.Resources.EngineHours;
}
else if (_helpSelected == "capacity")
{
htmlText = Properties.Resources.Capacities;
}
webBrowserView.NavigateToString(htmlText);
}
When run and the help file was selected, the following was displayed.
Upvotes: 0
Reputation: 8394
I think "test.html" is not valid name for resource. Try using "test_html" instead. Then the following works just fine.
private void button1_Click(object sender, EventArgs e)
{
string html = Properties.Resources.test_html;
webBrowser1.DocumentText = html;
}
So if HTML file is
<!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>
You'll end up with
Upvotes: 10