Click here to Skip to main content
14,739,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I'm also new to programming in C# and I need window insided my app that shows the directory struction of the C: and lets you select files just like Windows Explorer would. I'm assuming this is done with treeview? But I'm not able to find anything that shows me how to do this.

Please Help!

Thanks,
Chris
Posted
Comments
AspDotNetDev 24-Aug-10 15:15pm
   
Are you expecting the treeview to show the file system? It does not do that... it is a generic treeview that is not tied to the file system.

You should buy a basic book and read it. The OpenFileDialog and SaveFileDialog controls are what you want, but if you didn't know they existed, and didn't know how to find out about them, you must not have any references, and that's not going to work out for you.
   
There are plenty of tutorials/articles/tidbits on how to use the TreeView and how to inspect the file system. Did you try Googling?

One small point you'll want to consider. Since you don't want to load up the entire file system structure at once, you'll probably only want to load one level in the tree at a time. When a node is expanded, you'd then load all the folders in that folder. I'm sure there is an event on the TreeView you can use to implement this (e.g., Expanded or something along those lines).

http://www.c-sharpcorner.com/UploadFile/nkumar/WindowsExplorerinCSharp11292005230454PM/WindowsExplorerinCSharp.aspx
   
v2
Ever heard of google?

protected void AppendDirectoriesToTreeNode(TreeNode node, string root)
{
    DirectoryInfo rootDir = new DirectoryInfo(root);
    foreach (DirectoryInfo subDir in rootDir.GetDirectories())
    {
        TreeNode subdirNode = new TreeNode(subDir.Name);
        AppendDirectoriesToTreeNode(subdirNode, subDir.FullName);
        foreach (FileInfo fileInfo in subDir.GetFiles())
        {
            subdirNode.Nodes.Add(fileInfo.Name);
        }
        node.Nodes.Add(subdirNode);
    }
}


I googled this phrase:

"c# treeview folder hierarchy"

and got 334,000 results back.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900