TreeView folder hierarchy RRS feed

  • Question

  • I have the following task:

    Create a GUI application that will provide functionality to show complete hierarchy of files and folders
    for a specified folder:
    1. Each file/folder should be qualified with:
    a. File/Folder name
    b. File size (bytes) (only for files)
    (for folders only):
    c. Folder size
    d. Number of files
    The application needs to display the entire folder hierarchy tree by using the TreeView class.

    When a tree node is selected, the application needs to show the selected folder (or file)
    additional details:
    a. Creation time
    b. Last access time
    c. Last modified time
    The details should be shown in the same window but separately from the folder hierarchy tree

    I managed to get the folder and file names with this code from a tutorial:

    private void button1_Click(object sender, EventArgs e)
                ListDirectory(treeView1, "C:\\Users\\IGOR\\Desktop\\Bucky");
            private void ListDirectory(TreeView treeView, string path)
                var rootDirectoryInfo = new DirectoryInfo(path);
            private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
                var directoryNode = new TreeNode(directoryInfo.Name);
                foreach (var directory in directoryInfo.GetDirectories())
                foreach (var file in directoryInfo.GetFiles())
                    directoryNode.Nodes.Add(new TreeNode(file.Name));
                return directoryNode;

    For the rest of it i am pretty clueless. Can I actually show these properties in TreeView? What would be a good reference starting point?

    • Moved by CoolDadTx Monday, June 5, 2017 2:04 PM Winforms related
    Saturday, June 3, 2017 8:53 AM

All replies

  • Can't you use a built-in interface like IExplorerBrowser ?

    (it displays the Explorer in a window)

    Saturday, June 3, 2017 9:36 AM
  • Nope. The assignment was clear that is has to be a GUI.
    Saturday, June 3, 2017 9:56 AM
  • Nope. The assignment was clear that is has to be a GUI.
    I don't understand : IExplorerBrowser is a GUI...
    Saturday, June 3, 2017 10:14 AM
  • I mean't my GUI, not a built in one.
    Saturday, June 3, 2017 10:26 AM
  • Building an "Explorer"-like UI is a pretty standard homework assignment. Unfortunately we don't provide code for homework here but you can google for this and find plenty of examples of how to do this using Winforms.

    Michael Taylor

    Monday, June 5, 2017 2:04 PM
  • Thank you for the link. Could you recommend a good book that covers OOD principles in C# from a beginners point of view? 
    Tuesday, June 6, 2017 7:54 AM
  • Hi lgor,

    Sorry for the late reply.

    >>Could you recommend a good book that covers OOD principles in C# from a beginners point of view? 

    Please view the following book and it is suitable for beginners:

    Beginning C# 6 Programming with Visual Studio 2015

    And the following book is more suitable for middle and advanced users:

    Professional C# 5.0 and .Net 4.5.1

    In fact, MSDN has a lot of content for learning and I believe it is the best teacher.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites;
    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, June 14, 2017 7:31 AM
  • Add a context menu strip. Call the treeView1_RightClick method(Create it first), and check if the file is not a folder. If it is NOT A FOLDER, then allow the contextmenustrip to be shown, which has items like 'Properties..' or 'Copy..'

    Micah P.

    Wednesday, December 4, 2019 7:46 AM