Daniel
Daniel

Reputation: 1012

Loading a local html in WebBrowser

I am trying to load a local html file into a WebBrowser control. However, the resources that come with that html are added to the project but not loaded in the html. I copied them in the same directory, marked them as "copy-always" resources.

Since I am new to windows phone development, any help will be greatly appreciated. Thanks.

Upvotes: 0

Views: 1575

Answers (3)

Mas Isom Ajja
Mas Isom Ajja

Reputation: 11

(Assuming you have Help.html file in 'Help' folder of your project.)

if you're Mark the build action of the file as 'Content'

var rs = Application.GetResourceStream(new Uri("/Help/Help.html", UriKind.Relative));
StreamReader sr = new StreamReader(rs.Stream);
string htmlText = sr.ReadToEnd();
sr.Close();
webBrowser1.NavigateToString(htmlText);

if you're Mark the build action of the file as 'Resource'

var rs = Application.GetResourceStream(new Uri("/YOUR_PROJECT_NAME;component/Help/Help.html", UriKind.Relative));
StreamReader sr = new StreamReader(rs.Stream);
string htmlText = sr.ReadToEnd();
sr.Close();
webBrowser1.NavigateToString(htmlText);

Upvotes: 1

Amitd
Amitd

Reputation: 4859

Mark the build action for file as 'Content' from 'Properties' and then try the following :

(Assuming you have b.html file in 'html' folder of your project.)

  var rs = Application.GetResourceStream(new Uri("html/b.html", UriKind.Relative));
  StreamReader sr = new StreamReader(rs.Stream);
  string htmlText = sr.ReadToEnd();
  sr.Close();
  webBrowserCtrl.NavigateToString(htmlText) ;

Upvotes: 1

kadir
kadir

Reputation: 1417

You should mark the HTML File as Content. It should be "Resource" right now.

Upvotes: 0

Related Questions