[英]C#: How to load an internal .html file resource into a webbrowser control?
[英]How to load local HTML pages in WebBrowser control in C#
我有許多本地 HTML 頁面。 我想在 Web 瀏覽器控件中顯示這些本地 HTML 頁面。 當我添加新頁面時,它應該附加到上一頁。
這是設置 Url 的示例代碼
for( int i=0; i<=filecount; i++)
web-browser.Url = new Uri(filepath[i]);
但是在運行時它顯示文件下載彈出和網絡瀏覽器是空的。
您可以將單個頁面加載為
FileStream source = new FileStream(filepath, FileMode.Open, FileAccess.Read);
webBrowser1.DocumentStream = source;
甚至喜歡
string html = File.ReadAllText(filepath);
webBrowser1.DocumentText = html;
但是如果相對路徑中有圖像、css 或 js,請使用
Uri uri = new Uri(filepath);
webBrowser1.Navigate(uri);
webrowser.Navigate(filepath[i]);
我記得這樣的事情......;)
我試過了:
FileStream source = new FileStream(filepath, FileMode.Open, FileAccess.Read);
webBrowser1.DocumentStream = source;
我還必須添加這個:
webBrowser1.DocumentStream.Close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.