0

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");
 webb1.Navigate(uri);

I get the following error:

Cannot create instance of 'MainWindow' defined in assembly 'BB, Version=1.0.0.0, 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 ?

3
  • When you debug uri what does it give you? It shouldn't even let you do that statement. Commented Sep 17, 2013 at 13:18
  • if the html is in your bin folder, and you execute your program from debug/release folder, try new Uri("..\Rule1.html", UriKind.Relative); Commented Sep 17, 2013 at 13:23
  • The problem is Rule1.html is not in output folder.Click the "Rule1.html" and in Properties of that file set "Do not copy" to "Copy always".And then use the UriKind.Relative in creating Uri. Commented Sep 17, 2013 at 13:34

2 Answers 2

2

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."

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

System.Uri uri = new Uri("file://" + @"C:\Test\test.html", UriKind.Absolute);
webb1.Navigate(uri);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.