How to create an Explorer-like folder browser control?
Asked Answered
S

3

34

Using C# and WinForms in VS2008, I want to create a file browser control that looks and acts like the left pane in Windows Explorer. To my astonishment, such a control does not ship with .NET by default.

Ideally, I would like its contents to be exactly the same as in Explorer. For example, on Windows 7, it should show the Favorites and Libraries pseudo-folders. Of course, I do not want to code specifically for each version of Windows if I can help it.

I have browsed around, and there are some examples of such controls, but they are all hand-rolled and therefore won't work 100% the same as the one in Explorer.

Is there any way I can simply reuse the Explorer control instead? Or, if not, to get access to a tree of the items that it would show?

Shoulders answered 10/3, 2010 at 12:54 Comment(3)
I suspect the Explorer control just uses a tree control and populates it within the dialog code. I don't think it would be a specific control that displays the folders. I could be wrong.Necessarian
Are you looking for FolderBrowserDialog? ref: msdn.microsoft.com/en-us/library/…Voyles
@shahkalpesh: No, essentially I'm looking for the control used inside that dialog.Shoulders
F
33

Microsoft provides a walkthrough for creating a Windows Explorer style interface in C#.

There are also several examples on Code Project and other sites. Immediate examples are Explorer Tree, My Explorer, File Browser and Advanced File Explorer but there are others. Explorer Tree seems to look the best from the brief glance I took.

I used the search term windows explorer tree view C# in Google to find these links.

Flub answered 10/3, 2010 at 13:21 Comment(2)
Again, those are reinventing the wheel, and bound to get it wrong in various corner cases. But I'm accepting this because you provided the largest number of useful links.Shoulders
@Thomas: It think re-inventing the wheel is the only option you have as Windows doesn't expose that control for use outside of Explorer.Flub
S
1

It's not as easy as it seems to implement a control like that. Explorer works with shell items, not filesystem items (ex: the control panel, the printers folder, and so on). If you need to implement it i suggest to have a look at the Windows shell functions at http://msdn.microsoft.com/en-us/library/bb776426(VS.85).aspx.

Shrewd answered 10/3, 2010 at 13:1 Comment(1)
"It's not as easy as it seems to implement a control like that." I realize that. Which is exactly why I would prefer not to reinvent the wheel.Shoulders
W
0

Take a look at Shell MegaPack control set. It provides Windows Explorer like folder/file browsing with most of the features and functionality like context menus, renaming, drag-drop, icons, overlay icons, thumbnails, etc

Wo answered 10/3, 2010 at 13:39 Comment(1)
I had already run into that. If this weren't my first commercial application, I'd happily pay those $299, but as it stands, I can't afford that.Shoulders

© 2022 - 2024 — McMap. All rights reserved.