Setting WebBrowser.DocumentText = file.html?

Is it possible to set a WebBrowser.DocumentText file to a file without reading the file, setting its contents to a string variable, and then setting WebBrowser.DocumentText to this string variable? I would not mind writing code so much, it just looks like it should be possible without it.

+3
source share
4 answers

Do you mean "do not read the file yourself"? Although these examples include "reading the file yourself," they are pretty simple:

browser.DocumentStream = new FileStream("file.html", FileMode.Open, FileAccess.Read);

or

browser.DocumentText = File.ReadAllText("file.html")
+2
source

You can read the file in a line and set the property.

Note that MSDN says this:

, WebBrowser : URL- . , Navigating, Navigated DocumentCompleted , , Url .

, FileStream, , , DocumentStream.

0

As others have said, you can read the stream and set it to the DocumentStream property .

An alternative is to set the Url property using the url file:

webBrowser.Url = new Url(@"file://C:\file.html");
0
source

Use the method Navigate.

WebBrowser wb = new WebBrowse();
//Put it on a form 
wb.Navigate(filePath);

The file path should look like file://server/filename.extor file://C:/path/filename.ext.

0
source

Source: https://habr.com/ru/post/1791309/


All Articles