c# webbrowser control displaying “special folder” contents : why are Document and DocumentDom always null?

StackOverflow https://stackoverflow.com/questions/1480965

  •  18-09-2019
  •  | 
  •  

Question

In a C# WinForms, .NET Framework 3.5, project with a WebBrower control on the form :

... with a project reference set to MSHTMLdll and the WinForm code : "using mshtml;" ...

  1. you can load a "special folder," like the Favorites folder, into the browser easily.

  2. after you've loaded a "special folder" : what appears in the WebBrowser is essentially a kind of "explorer" view : you have the choice of typical "explorer" view-styles of 'Details, etc. in Details view you have a row-column matrix, with typical "Explorer" style column heads, etc.

Normally I would "get at" the DOM of the WebBrowser via casting the Document, or the DomDocument of the Document, to the IHTMLDocument2 interface exposed by mshtml.dll :

IHTMLDocument2 HTMLDocument = (IHTMLDocument2)webBrowser1.Document;

// also tried this

// IHTMLDocument2 HTMLDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;

// also tried this

// HTMLDocumentClass HTMLDocument = webBrowser1.Document.DomDocument as HTMLDocumentClass;

But in this case, viewing a "special folder" contents, I'm always getting the Document as null.

It is interesting that you can while viewing a special folder, like the Favorites, create a new folder and do other "file ops" : I wonder if I am "getting away with this" because I have protected mode turned off on IE8 ?

Appreciate any ideas about how to access the DOM while viewing special folder in the WebBrowser controls.

thanks ! Bill

Was it helpful?

Solution

The folder view isn't HTML document, so you can not use HTML interface to access the content. Use shell interfaces like IShellBrowser, IShellView and IFolderView if you are really interested in what's displayed in the window.

OTHER TIPS

Typically the webbrowser's document property will be null until a page is loaded. You can try this to initialize the document property:

webBrowser1.Navigate("about:blank"); while (webBrowser1.Document.Body == null) Application.DoEvents(); // now you can access the Document property, including getting/setting the innerHtml

However, I'm not sure this will help you since the fact that the Document property is null, while you are still viewing what you want to see, suggests that even when the Document property is no longer null, that will not be the way to access the special folder data. But you can try the above code, then loading your special folder, and then looking at the document and see what you get...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top