0

In my WPF app I am trying to load an html file(from inside my project, name of html file is index.html) in to a WebBrowser component.

I followed an answer byghostJago from this question: Load local HTML file in a C# WebBrowser , but the problem is, the directory of the html file I get points to a Debug folder ( E.g C:\Users\user1\source\repos\AppName\AppName\bin\Debug ).

The first time I ran my project in debug mode, the html file wasn't in the debug folder, I had to paste it in there. So is it possible to load a html file from within visual studio project at runtime? If so, how do I do it?

Code that points to Debug folder:

string curDir = Directory.GetCurrentDirectory();
string myFile = System.IO.Path.Combine(curDir, "index.html");
WebView.Navigate("file:///" + myFile);
Tân
  • 1
  • 15
  • 56
  • 102
Tyron
  • 114
  • 1
  • 3
  • 13

1 Answers1

0

If you have a file listed in Visual Studios solution explorer, you should be able to right click it, select properties and in the properties pane set the "Copy to Output Directory" to "Copy always".

The file will then end up next to the exe in the same debug folder and you will be able to refer to it with your existing code.

D Coder
  • 31
  • 3