How to load local HTML pages in WebBrowser control

2020-02-11 04:01发布

I have number of local HTML pages. I want to display these local HTML pages in Web browser control. When I add new page it should get append to previous page.

Here is the sample code for the setting Url

for( int i=0; i<=filecount; i++)
    web-browser.Url = new Uri(filepath[i]);

But during run time its showing the File Download pop up and web browser is empty.

3条回答
小情绪 Triste *
2楼-- · 2020-02-11 04:21

You could load a single page as

FileStream source = new FileStream(filepath, FileMode.Open, FileAccess.Read);
webBrowser1.DocumentStream = source;

or even like

string html = File.ReadAllText(filepath);
webBrowser1.DocumentText = html;

But if you have images, css or js in the relative paths, use

Uri uri = new Uri(filepath);
webBrowser1.Navigate(uri);
查看更多
家丑人穷心不美
3楼-- · 2020-02-11 04:22
webrowser.Navigate(filepath[i]); 

something like that i remember... ;)

查看更多
走好不送
4楼-- · 2020-02-11 04:38

I tried:

FileStream source = new FileStream(filepath, FileMode.Open, FileAccess.Read);
webBrowser1.DocumentStream = source;

I had to add this also:

webBrowser1.DocumentStream.Close();
查看更多
登录 后发表回答