tags:

views:

138

answers:

1

I’m working with the WPF WebBrowser control to navigate to a html page hosting Silverlight. It seems I cannot use the NavigateToString or NavigateToStream method since I have Silverlight content. The html content loads fine but not Silverlight. So I think I’ll have to use the Navigate method which takes an Uri. Now I html page I’d like to navigate to is in a .html file in my Visual Studio project so I will have to have a local uri of some sort. I don’t want the html file to be copied to the output folder since I don’t want to distribute it separately; I want it to be somehow included in the assembly. The problem is that the WebBrowser control doesn’t seem to allow relative Uris or pack://application: uris.

How could I accomplish navingating to an .html file in the assembly?

A: 

You should be able to use NavigateToString and pull the HTML file out yourself using GetManifestResourceStream:

using (var _textStreamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("BrowserTest.test.htm")))
{
    string content = _textStreamReader.ReadToEnd();
    MainBrowser.NavigateToString(content);
}

You're going to have issues if you need to use external resources in your HTML file though. If you need external resource then you're going to have to embed Win32 resources (not the same thing as .net resources) into your assembly, which is a bit of a pain. There's an example of doing this in a WinForms app over on CodeProject.

Steven Robbins