Click here to Skip to main content
11,410,750 members (63,689 online)
Click here to Skip to main content

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.

Comments and Discussions

GeneralException removing folder with Directory.Delete PinmemberSergio Camilleri30-Mar-05 2:55 
QuestionExcellent - License? PinsussAnonymous3-Mar-05 14:17 
AnswerRe: Excellent - License? PinmemberFurty18-Mar-05 13:17 
GeneralGreat stuff Pinmemberderhamyh2-Mar-05 16:36 
GeneralExcellent! Pinmemberscottfm28-Jan-05 10:27 
QuestionAnyone had luck with fileSystemWatcher with this control? PinmemberIndyJason7911-Jan-05 1:52 
GeneralTip to remove Recyle Bin & Zip File Nodes PinmemberIndyJason792-Jan-05 18:59 
GeneralRe: Tip to remove Recyle Bin & Zip File Nodes PinmemberNigai18-Mar-05 9:44 
Hello IndyJason79! I think your idea is right. It's better that zip files or Recycle Bin is not selectable.
But your solution will cause a trouble in a very uncommon and arbitrary case.
If a normal folder named "Recycle Bin" is on the desktop, it won't be shown same as true Recycle Bin.
I know that there's a kind of people who loves to go on such spiteful ways.Frown | :(

Add this code under "tree.Nodes.Add(desktop);"
// Get FolderItem that represents Recycle Bin
Shell32.Folder rFolder = shell32.NameSpace(ShellFolder.RecycleBin);
Shell32.FolderItem recycle = null;
foreach (Shell32.FolderItem fi in rFolder.ParentFolder.Items())
    if (fi.Name == rFolder.Title)
        recycle = fi;

And modify like this.
// Added criteria not to show zip files and recycle bin
if (item.IsFolder && !item.IsBrowsable && item.Path != recycle.Path)


GeneralThis in VB?.... PinmemberBrad Fackrell26-Oct-04 5:33 
GeneralRe: This in VB?.... Pinmemberzsavov30-Mar-05 17:27 
GeneralName of the root node PinmemberNigai10-Oct-04 10:49 
GeneralRe: Name of the root node PinmemberFurty10-Oct-04 15:01 
GeneralRe: Name of the root node PinmemberNigai11-Oct-04 21:42 
GeneralMy network places - Windows 2000 Pinmembergraham.ball19-Aug-04 4:42 
GeneralRe: My network places - Windows 2000 Pinmembergraham.ball19-Aug-04 5:34 
GeneralGetFolderIcon PinmemberYura Tigiev26-Jul-04 0:17 
Generalmy network places Pinmemberthen52030-Mar-04 22:52 
GeneralWindows XP shadow Pinmemberaiolia9-Feb-04 17:15 
GeneralRe: Windows XP shadow Pinmemberdgentils8-Mar-04 18:03 
GeneralRe: Windows XP shadow Pinmembera020912926-Mar-04 13:17 
GeneralRe: Windows XP shadow Pinmemberdgentils26-Mar-04 14:12 
GeneralRe: Windows XP shadow Pinmembera020912927-Mar-04 8:32 
GeneralRe: Windows XP shadow Pinmembersilas_yao28-Sep-04 6:28 
GeneralFile Names Pinmemberjpadova19-Feb-04 8:07 
GeneralRe: File Names PinmemberIndyJason792-Jan-05 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.150414.5 | Last Updated 26 Oct 2002
Article Copyright 2002 by Furty
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid