Only access WebBrowser.Document after DocumentCompleted event

The last couple of days I have stumbled upon a similar problem from different users on the MSDN forums.
 
It seems to be a problem that the Document property of the WebBrowser control is accessed before DocumentCompleted event has been raised. This will give you a HtmlDocument instance that is as good as empty and it does not represent the document that it will be when it is completed.
 
After the web browser control has started to navigate only access the Document, DocumentText and DocumentStream properties after DocumentCompleted event has been raised.
 
The MSDN article for the DocumentCompleted event contains example code how to implement the event handler.

Leave a Reply

Your email address will not be published. Required fields are marked *