The HTMLDocument property is used to return a reference to an HTML document object that is running inside a custom task pane. This property is one of the inherited properties of the TaskPane object when the type is 0 (custom task pane).
The following example shows how to set a reference to a custom task pane object using the HTMLTaskPane object running inside a custom task pane:
var objHTMLDocument; objHTMLDocument = XDocument.View.Window.TaskPanes(0).HTMLDocument;