Home > DeveloperSection > Forums > How to use an HTML file in WPF
Alex Leblois
Alex Leblois

Total Post:67

Posted on    September-23-2013 8:11 AM


 1 Reply(s)
 882  View(s)
Rate this:

I have a WPF project with a WebBrowser control. I want to navigate to a HTML page that is in the project. When I build my project there is an HTML file called Rule1.html in my bin folder. I have tried the following:

 System.Uri uri = new Uri("Rule1.html");


I get the following error:

Cannot create instance of 'MainWindow' defined in assembly 'BB, Version=, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'MainWindow.xaml' Line 1 Position 9.

When I use an absolute Uri the program and control work fine, but I only want to use html pages that exist in my application for the time being. How can I accomplish this ?

Pravesh Singh

Total Post:411

Posted on    September-23-2013 8:34 AM

Hi Alex,

I'm not sure if that URI creation statement even works, it doesn't seem to run on my machine.

You have to specify a path for it.

Uri uri = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"\Rule1.html");

AppDomain.CurrentDomain.BaseDirectory "gets the base directory that the assembly resolver uses to probe for assemblies."

Don't want to miss updates? Please click the below button!

Follow MindStick