Showing directory structure in TreeView control using c# :
This blog will walk you through using a tree view control of the windows forms application in .net to show the directory structure on your computer. Create a windows form application in visual studio. Drag and drop the tree view control on the form design.

Code at Form load :
Here we specify the Directory path from where we want to show the directory structure and call a method to populate the treeView.
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo root = new DirectoryInfo(@"D:\folder");
TreeNode node = populateTree(root,null);
treeView1.Nodes.Add(node);
}
Now we write the method populateTree which is called in the form load. This method is recursively called which allows it to read through the nesting of the directories.



Join the conversation! Your thoughts help the community grow.