MS WebBrowser + Embedded HTML Resource + res:// Protocol

user144051 picture user144051 · Aug 10, 2009 · Viewed 14.3k times · Source

I have an embedded HTML resource (helloworld.htm) inside my Visual Studio project. (Ie, I've added an HTML file to the project and set its properties to "Embedded Resource".

Within the same application I have a WebBrowser control.

I'd like to direct the WebBrowser control to display the HTML resource using the res:// protocol.

But I can't figure out the exact format needed to address an embedded resource using this style of URL.

Any ideas? Thanks!

Answer

Chris Barlow picture Chris Barlow · Feb 3, 2011

I know this thread is dead, but I had to do this yesterday and couldn't get any of these methods to work. So I did a little research and found the method below, using the Stream class. I thought I'd post it here just in case somebody else runs into the same nonsense:

Stream docStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NameSpace.HTMLPage.html");
WebBrowser.DocumentStream = docStream;

This worked for me without any tinkering, and it was so simple. I hope it benefits somebody else!