简体   繁体   English

如何在 C# 中的 WebBrowser 控件中加载本地 HTML 页面

[英]How to load local HTML pages in WebBrowser control in C#

I have number of local HTML pages.我有许多本地 HTML 页面。 I want to display these local HTML pages in Web browser control.我想在 Web 浏览器控件中显示这些本地 HTML 页面。 When I add new page it should get append to previous page.当我添加新页面时,它应该附加到上一页。

Here is the sample code for the setting Url这是设置 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但是如果相对路径中有图像、css 或 js,请使用

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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