开发者

Windows Phone 7 Web Browser Navigating to an html file located in a folder within the solution

Uri currURI = new Uri(currentPageToLoad, UriKind.Relative); ExtrasHTMLbrowser.Navigate(currURI);

The above code basically is grabbing a string (currentPageToLoad) and making a URI. Then my web browser, ExtrasHTMLbrowser, is trying to navigate to the URI. When currentPageToLoad is something like "author.html"开发者_运维问答 it works perfectly, and navigates to the html page.

However, the problem I am having is that when the html file is in a folder such as HTML, it won't navigate properly. So, when currentPageToLoad = "HTML/author.html" the phone will give me the generic 404 not found page.

Any Idea why it would matter if the file was in a folder, or am I trying to access the file incorrectly?

Any help is greatly appreciated, thanks! -Mark


Set the HTML file to build type Content.Then do this:

var rs = Application.GetResourceStream(new Uri("HTML/author.html", UriKind.Relative));
StreamReader sr = new StreamReader(rs.Stream);

This will read the entire HTML file as a string. You can then use the WebBrowser control's NavigateToString method like this:

ExtrasHTMLbrowser.NavigateToString(sr.ReadToEnd());

If you have images/CSS you want to use, then you'll have to use the above method to read the HTML file as a string and save it into Isolated Storage, alongside the images and CSS files (with matching directories).


In order to be able to navigate between multiple pages you'll first need to copy the files to IsolatedStorage. It's not possible to navigate between pages if you navigate to a file directly within the XAP. (The relative paths are unusable and you can't access such files via an absolute Uri.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜