3

I need help in displaying HTML File in webbrowser in Windows phone 7 app.

I've an html file in my wpf-silverlight project as resource. Now When the user click on Help button in my App, i need to display this HTML in webbrowser.

Here is the code, which is giving me an error -

webBrowser1.Navigate(new Uri("AppHelp.html",UriKind.Relative))

But, if i use this code, It's loading fine

webBrowser1.Navigate(new Uri("http://mywebsite.com/AppHelp.html",UriKind.Relative))

Please help!

I've change code like this now, but now i'm getting this error:Invalid URI: A Port is signaled with ':' but could not be parsed.

   Uri uri = new Uri(@"pack://application:AppHelp.html", UriKind.Absolute);
    Stream stream = Application.GetResourceStream(uri).Stream;
    using (StreamReader reader = new StreamReader(stream))
    {
        // Navigate to HTML document string
        this.webBrowser1.NavigateToString(reader.ReadToEnd());
    }
Pavan
  • 99
  • 1
  • 12

2 Answers2

1

You can try this,

http://www.c-sharpcorner.com/uploadfile/raj1979/how-to-embed-html-file-in-windows-phone-7/

and for with image in html

you can this, Use local images in Webbrowser control

using IsolatedStorages

Community
  • 1
  • 1
1

You can use method NavigatedToString of WebBrowse object by getting content of html file and put it as parameter of this method.

http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.navigatetostring.aspx

samples at: http://blogs.msdn.com/b/mikeormond/archive/2010/12/16/displaying-html-content-in-windows-phone-7.aspx

  • Here is my Code and I'm getting this eror(Invalid URI: A Port is signaled with ':' but could not be parsed.) Uri uri = new Uri(@"pack://application:AppHelp.html", UriKind.Absolute); Stream stream = Application.GetResourceStream(uri).Stream; using (StreamReader reader = new StreamReader(stream)) { // Navigate to HTML document string this.webBrowser1.NavigateToString(reader.ReadToEnd()); } – Pavan Nov 08 '11 at 01:45
  • set build option of your html file as "content" and get stream: Application.GetResourceStream(new Uri("yourfilename.html", UriKind.Relative)); – Damian Jarosch Nov 08 '11 at 03:05
  • 1
    NavigateToString does not play nice with images, though – Esa Jun 29 '12 at 09:09
  • Many Thanks ..! faced same problem of URI but that too resolved. :) – ameya rote Jan 23 '13 at 14:54