0

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.

Daniel
  • 984
  • 8
  • 14
  • I finally found the answer after digging a bit longer. The solution was to copy the resources in the isolated storage and then create a relative URI for loading the local HTML. From here: http://stackoverflow.com/questions/10363174/use-local-images-in-webbrowser-control-wp7/10363410#10363410 – Daniel May 15 '12 at 07:21

3 Answers3

1

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) ;
Amitd
  • 4,769
  • 8
  • 56
  • 82
1

(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);
0

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

kadir
  • 1,417
  • 11
  • 35