Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i get the selected file in the active explorer window?

390 views
Skip to first unread message

cipher

unread,
Feb 4, 2009, 2:46:19 AM2/4/09
to
Hi I would like to get the selected file path from the active explorer
window, can this be done?
I would be doing this in c# but any language will do.

Thanks

Jim Barry

unread,
Feb 4, 2009, 6:10:41 AM2/4/09
to
cipher wrote:
> Hi I would like to get the selected file path from the active explorer
> window, can this be done?

You can use the ShellWindows object to enumerate the collection of shell windows. Each item is an InternetExplorer object that supports an "HWND" property, which you could use to determine whether it is the active window. If the item is a normal Explorer window then the "Document" property exposes an IShellFolderViewDual2 interface, which provides a SelectedItems method allowing you to get the path of any selected items.

ShellWindows Object: http://msdn.microsoft.com/en-us/library/bb773974.aspx
InternetExplorer Object: http://msdn.microsoft.com/en-us/library/aa752084.aspx
ShellFolderView Object: http://msdn.microsoft.com/en-us/library/bb774049.aspx

--
Jim Barry, Microsoft MVP

mayayana

unread,
Feb 4, 2009, 10:02:43 AM2/4/09
to
As Jim Barry said, you can use Shell.Windows.
It returns IE objects, sort of. It actually returns a
somewhat bizarre collection of all open instances
of IE and Explorer, treating them as though they
were the same thing. You have to differentiate
between them.

The idea of an IE object with folders is misleading. It's a leftover
from the days of Active Desktop and WebView, when MS
was desperately trying to make Windows look Web-integrated
and "hip". On pre-XP systems there actually is an IE
browser window in folder windows. On XP, Shell.Windows
returns dummy IE instances for folders -- WebView was
removed in XP -- but the dummy still works for your purpose.

On all systems the dummy IE.Document returns not a real IE
Document object but rather a ShellFolderView object. (It
takes an extra step to get the actual IE Document object
that exists on WebView systems.)

The SFV is a COM wrapper around the ListView window
that actually displays files in a folder window. The whole
Shell object model is a bit convoluted and piecemeal, but SFV
does have a SelectedItems collection that you can use.

If you can work with VB code (not VB.Net), see here:

www.jsware.net/jsware/vbcode.php5#shlop

It's a VB project that demostrates 3 different ways to
get at a folder's selected items:

1) Getting a ShellFolderView as an embedded object on
the folder.htt webpage on pre-XP systems -- works on
Win95 -> 2000 with Active Desktop.

2) Getting a ShellFolderView from the dummy IE.Document
available via Shell.Windows -- should work on all systems
but requires Active Desktop update on Win95/NT4.

3) Getting selected items through Active Accessibility,
which is in oleacc.dll. Oleacc.dll is available since Win98SE.

cipher

unread,
Feb 4, 2009, 11:17:22 PM2/4/09
to
On Feb 4, 7:02 am, "mayayana" <mayaXXy...@rcXXn.com> wrote:
>    As Jim Barry said, you can use Shell.Windows.
> It returns IE objects, sort of. It actually returns a
> somewhat bizarre collection of all open instances
> of IE andExplorer, treating them as though they

> were the same thing. You have to differentiate
> between them.
>
>   The idea of an IE object with folders is misleading. It's a leftover
> from the days ofActiveDesktop and WebView, when MS

> was desperately trying to make Windows look Web-integrated
> and "hip". On pre-XP systems there actually is an IE
> browserwindowin folder windows. On XP, Shell.Windows

> returns dummy IE instances for folders -- WebView was
> removed in XP -- but the dummy still works for your purpose.
>
>   On all systems the dummy IE.Document returns not a real IE
> Document object but rather a ShellFolderView object. (It
> takes an extra step togetthe actual IE Document object

> that exists on WebView systems.)
>
>   The SFV is a COM wrapper around the ListViewwindow
> that actually displays files in a folderwindow. The whole

> Shell object model is a bit convoluted and piecemeal, but SFV
> does have a SelectedItems collection that you can use.
>
>   If you can work with VB code (not VB.Net), see here:
>
> www.jsware.net/jsware/vbcode.php5#shlop
>
>   It's a VB project that demostrates 3 different ways togetat a folder'sselecteditems:
>
> 1) Getting a ShellFolderView as an embedded object on
> the folder.htt webpage on pre-XP systems -- works on
> Win95 -> 2000 withActiveDesktop.
>
> 2) Getting a ShellFolderView from the dummy IE.Document
> available via Shell.Windows -- should work on all systems
> but requiresActiveDesktop update on Win95/NT4.
>
> 3) Gettingselecteditems throughActiveAccessibility,
> which is in oleacc.dll. Oleacc.dll is available since Win98SE.
>
> > Hi I would like togettheselectedfilepathfrom theactiveexplorer
> >window, can this be done?
> > I would be doing this inc#but any language will do.
>
> > Thanks

Thank you both very much! this was very helpful.

0 new messages