简体   繁体   中英

How to load local HTML pages in WebBrowser control in C#

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.

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);
webrowser.Navigate(filepath[i]); 

我记得这样的事情......;)

I tried:

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

I had to add this also:

webBrowser1.DocumentStream.Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM