views:

453

answers:

2

Hi,

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

A: 

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...

Trey
Hi Trey, Thanks for your response ! In this case, you can be sure that I have carefully "waited" via code until the page is loaded using the standard method.I do believe, now, that when viewing such special folders the WebBrowser is in some "altered state" where the "view" is a kind of pseudo-Explorer view, and that in that state the DOM cannot be accessed, however, I hope to be proven wrong :)best, Bill
BillW
+1  A: 

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.

Sheng Jiang 蒋晟
Hi Sheng Jiang, thanks for your suggestions ! In this case the contents I am displaying are the Favorites folder for IE8. I will try and experiment with the interfaces you mention. best, Bill
BillW