I have this piece of code:
WebBrowser wb = new WebBrowser();
wb.Navigate(URL);
HtmlDocument doc = wb.Document;
I should mention, that I have no WebBrowser Control on a form, it's just in method in my class. After this, wb.Document and doc as well are nulls. Why is that? What do I have to do to obtain this document?
You should handle the DocumentCompleted event and access the document in your event handler when that fires.
Navigation and document loading is handled asynchronously - therefore the control hasn't actually navigated or loaded anything when the Navigate
method returns; hence why these are null.
It's always null because it hasen't loaded yet.
What you need to do is subscribe to the webBrowser.DocumentCompleted event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With