2012-07-05 80 views
1

我试图在Windows Phone 7.1的WebBrowser中加载本地文件,但我总是收到异常或空白页。在WebBrowser控件中加载本地文件

我试着用

Stream stream = Application.GetResourceStream(
        new Uri("./Html/par/index.html", 
        UriKind.Relative)).Stream; 
using (StreamReader reader = new StreamReader(stream)) 
{ 
    // Navigate to HTML document string 
    this.webBrowser.NavigateToString(reader.ReadToEnd()); 
} 

这是发射一个空白页。

我将index.html和所有需要的文件(css/js)设置为Content和IsScriptEnable为“true”。

你知道如何解决这个问题吗?

回答

2

我认为路径不正确。

你有/Html/par目录在你的项目?其次是index.html设置为内容?

尝试

var rs = Application.GetResourceStream(new Uri("myFile.html", UriKind.Relative)); 
using(StreamReader sr = new StreamReader(rs.Stream)) 
{ 
    this.webBrowser.NavigateToString(sr.ReadToEnd()); 
} 

这可能帮助 http://phone7.wordpress.com/2010/08/08/loading-a-local-html-file-in-the-webbrowser-control/

这可能帮助资源和内容之间undertand差异 http://invokeit.wordpress.com/2011/09/30/images-and-build-actio-settings-in-wp7/

此链接细节如何加载文件和其他链接文件 http://transoceanic.blogspot.co.uk/2011/07/wp7-load-local-html-files-and-all.html

+0

StreamReader reader = new StreamReader(TitleContainer.OpenStream(“test.html”)); webBrowser1.NavigateToString(reader.ReadToEnd()); 我也使用过这个。问题不在于路径,而是实际上它加载了指定的html,而不是本地脚本/样式文件/图像。 任何想法如何流这些文件呢? – fran 2012-07-05 10:44:15

+1

尝试此链接http://transoceanic.blogspot.co.uk/2011/07/wp7-load-local-html-files-and-all.html – 2012-07-05 10:58:59

+0

谢谢!!它的工作就像一个魅力,但它是一种耻辱,我们有要做到这一点加载本地文件...我希望有第二种方式......但这是最好的答案!干杯! – fran 2012-07-05 12:33:13

相关问题