Click here to Skip to main content
12,295,876 members (32,391 online)
Click here to Skip to main content
Add your own
alternative version


126 bookmarked

FolderTreeView Control

, 25 Oct 2002
Rate this:
Please Sign up or sign in to vote.
A simple explorer-like FolderTreeView control for C#

Sample Image


This is an all-new version of the FolderTreeView control I posted here at CodeProject some weeks ago. The control now starts in the Desktop namespace, and a new drilling method has been added so the startup folder can be specified. Please note that this control is not intended to have all of the functionality of the actual Windows Explorer TreeView - it is a light-weight control designed for use in projects where you want to supply a treeview for folder navigation, without supporting windows shell extensions. If you are looking for a control that supports shell extensions you should be looking at the excellent ËxplorerTreeControl submitted by Carlos H Perez here at the CodeProject website.

How it works

After calling the InitFolderTreeView() method, a dummy Desktop not is created as the root node, and then the shell's Desktop namespace is iterated to populate the first level nodes. The child nodes are then iterated, checking only for the presence of sub-child nodes. If sub-child nodes are found, a dummy node is inserted so that the [+] will be displayed for folders that can be expanded. When the BeforeExpand event fires, the folder being expanded is checked for a dummy node. If a dummy is present, it is removed and the node's children are re-populated. If the node's children have already been populated no further action occurs.


The FolderTreeView control is based on 3 classes:

  • FolderTreeView - The FolderTreeView implementation
  • ShellOperations - Supporting Shell Operations
  • ExtractIcons - Shell Icon Extractor
The control naturally derives from the System.Windows.Forms.TreeView, exposing 1 new property, GetSelectedNodePath() which returns the currently selected node's full path. There are 2 new methods: InitFolderTreeView() must be called to populate the TreeView - normally you would call this in your Form's OnLoad event. The 2nd method is DrillToFolder(string folderPath) - this will recurse through the tree looking for the specified folder path, returning a boolean to indicate if the search was sucessful or not.

The method used to retreive the icon for the Desktop root node works fine, but is perhaps not the best way to go about it. This control has NOT been tested in Win9x, NT or 2000 - feedback on these OS's would be much appreciated. Of course if you improve this control I would appreciate the update, and if you have any feedback to offer, please post it below.


Version 1.11:

  • Updated the GetDesktopIcon() method so it returns the shell's small desktop icon rather than the large version
  • Added code so that the Desktop node would return the full desktop folder path
I have now tested the code on Windows Me without problem - feeback on how it works with other OS's would be appreciated!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Thailand Thailand
Furty will code for food.

You may also be interested in...

Comments and Discussions

AnswerPossible Improvement to DrillToFolder() Pin
Charles Jenkins9-Oct-14 3:25
memberCharles Jenkins9-Oct-14 3:25 
GeneralNot able to see Entire Network in My Network Places Pin
remane24-May-07 2:34
memberremane24-May-07 2:34 
GeneralCompiling on Vista, executing on XP - error Pin
splattne215-Mar-07 3:55
membersplattne215-Mar-07 3:55 
QuestionRe: Compiling on Vista, executing on XP - error Pin
Dynamite Jones27-Jul-07 5:37
memberDynamite Jones27-Jul-07 5:37 
AnswerWhy are you Developing on Vista!? Pin
redfish3411-Oct-07 14:05
memberredfish3411-Oct-07 14:05 
GeneralRe: Why are you Developing on Vista!? Pin
datacore29-Oct-08 21:22
memberdatacore29-Oct-08 21:22 
QuestionHow to remove the A: drive(diskette) from the tree? Pin
rytek909-Feb-07 4:47
memberrytek909-Feb-07 4:47 
QuestionConnection to Live ID? Pin
Seikilos11-Jan-07 9:57
memberSeikilos11-Jan-07 9:57 
AnswerRe: Connection to Live ID? Pin
Seikilos15-Jan-07 7:44
memberSeikilos15-Jan-07 7:44 
QuestionHourglass Cursor in ExpandBranch Pin
goondoo2717-Nov-06 12:20
membergoondoo2717-Nov-06 12:20 
AnswerRe: Hourglass Cursor in ExpandBranch Pin
goondoo2720-Nov-06 6:08
membergoondoo2720-Nov-06 6:08 
QuestionHow To Remove Network Neighbourhood, Internet Explorer and Recyle Bin ? Pin
scorpion_pgm8230-Aug-06 2:22
memberscorpion_pgm8230-Aug-06 2:22 
GeneralList All Computers in the network Pin
Shailesh Halankar28-May-06 23:35
memberShailesh Halankar28-May-06 23:35 
GeneralRe: List All Computers in the network Pin
datacore22-Jun-06 20:58
memberdatacore22-Jun-06 20:58 
QuestionProblem with icons colors Pin
Galanty22-Mar-06 23:43
memberGalanty22-Mar-06 23:43 
AnswerRe: Problem with icons colors Pin
sir_mad23-Mar-06 0:15
membersir_mad23-Mar-06 0:15 
GeneralRe: Problem with icons colors Pin
Galanty24-Mar-06 8:21
memberGalanty24-Mar-06 8:21 
AnswerRe: Problem with icons colors Pin
nguyen_freddie17-Jan-10 17:55
membernguyen_freddie17-Jan-10 17:55 
GeneralDrillToFolder and unc-path Pin
tabor252-Mar-06 5:29
membertabor252-Mar-06 5:29 
GeneralPay attention to shell extensions Pin
Liviu7-Feb-06 4:10
memberLiviu7-Feb-06 4:10 
QuestionRe: Pay attention to shell extensions Pin
sir_mad22-Mar-06 4:53
membersir_mad22-Mar-06 4:53 
QuestionWhat about the hidden directory ? Pin
bilb0t1-Feb-06 3:22
memberbilb0t1-Feb-06 3:22 
GeneralExcellent Pin
-Dy24-Jan-06 10:25
member-Dy24-Jan-06 10:25 
GeneralPerformance and network neighbourhood Pin
rubberring8-Nov-05 10:32
memberrubberring8-Nov-05 10:32 
GeneralRe: Performance and network neighbourhood Pin
dario7711-Jan-06 7:06
memberdario7711-Jan-06 7:06 
QuestionControl in Designer with DLL Compilation Pin
akiriwas8-Oct-05 17:13
memberakiriwas8-Oct-05 17:13 
AnswerRe: Control in Designer with DLL Compilation Pin
Gav_Roberts2k518-Oct-05 3:03
memberGav_Roberts2k518-Oct-05 3:03 
QuestionHow to add create/delete folder? Pin
Tiger xing7-Oct-05 19:18
memberTiger xing7-Oct-05 19:18 
GeneralException removing folder with Directory.Delete Pin
Sergio Camilleri30-Mar-05 1:55
memberSergio Camilleri30-Mar-05 1:55 
QuestionExcellent - License? Pin
Anonymous3-Mar-05 13:17
sussAnonymous3-Mar-05 13:17 
AnswerRe: Excellent - License? Pin
Furty18-Mar-05 12:17
memberFurty18-Mar-05 12:17 
GeneralGreat stuff Pin
derhamyh2-Mar-05 15:36
memberderhamyh2-Mar-05 15:36 
GeneralExcellent! Pin
scottfm28-Jan-05 9:27
memberscottfm28-Jan-05 9:27 
QuestionAnyone had luck with fileSystemWatcher with this control? Pin
IndyJason7911-Jan-05 0:52
memberIndyJason7911-Jan-05 0:52 
GeneralTip to remove Recyle Bin & Zip File Nodes Pin
IndyJason792-Jan-05 17:59
memberIndyJason792-Jan-05 17:59 
GeneralRe: Tip to remove Recyle Bin & Zip File Nodes Pin
Nigai18-Mar-05 8:44
memberNigai18-Mar-05 8:44 
GeneralThis in VB?.... Pin
Brad Fackrell26-Oct-04 4:33
memberBrad Fackrell26-Oct-04 4:33 
GeneralRe: This in VB?.... Pin
zsavov30-Mar-05 16:27
memberzsavov30-Mar-05 16:27 
GeneralName of the root node Pin
Nigai10-Oct-04 9:49
memberNigai10-Oct-04 9:49 
GeneralRe: Name of the root node Pin
Furty10-Oct-04 14:01
memberFurty10-Oct-04 14:01 
GeneralRe: Name of the root node Pin
Nigai11-Oct-04 20:42
memberNigai11-Oct-04 20:42 
GeneralMy network places - Windows 2000 Pin
graham.ball19-Aug-04 3:42
membergraham.ball19-Aug-04 3:42 
GeneralRe: My network places - Windows 2000 Pin
graham.ball19-Aug-04 4:34
membergraham.ball19-Aug-04 4:34 
GeneralGetFolderIcon Pin
Yura Tigiev25-Jul-04 23:17
memberYura Tigiev25-Jul-04 23:17 
Generalmy network places Pin
then52030-Mar-04 21:52
memberthen52030-Mar-04 21:52 
GeneralWindows XP shadow Pin
aiolia9-Feb-04 16:15
memberaiolia9-Feb-04 16:15 
GeneralRe: Windows XP shadow Pin
dgentils8-Mar-04 17:03
memberdgentils8-Mar-04 17:03 
GeneralRe: Windows XP shadow Pin
a020912926-Mar-04 12:17
membera020912926-Mar-04 12:17 
GeneralRe: Windows XP shadow Pin
dgentils26-Mar-04 13:12
memberdgentils26-Mar-04 13:12 
GeneralRe: Windows XP shadow Pin
a020912927-Mar-04 7:32
membera020912927-Mar-04 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 26 Oct 2002
Article Copyright 2002 by Furty
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid