How do I display files and folder in a directory using the tree control.
Sample is provided in this thread that will display the files and folders in the tree control by specifying a path in the textbox and clicking on the Load button. The following solution uses the WebDataTree control and an XmlDataSource. In the WebDataTree you can set the NodeBindings of the DataMember and TextField so that the control will display the attribute value instead of the element that is contained in the xml data.
To create xml data is to simply use the XmlDocument class, create the declaration, and the root node. Then an instance of the DirectoryInfo class is created and path is specified using the TextBox. Within the DirectoryInfo instance contains GetDirectories() and GetFiles() methods that will return as an array of DirectoryInfo and FileInfo. Finally then looping through the directory and file information and constructing the xml.
This is just a sample that provides 2 levels of the hierarchy. If for example you wanted to return all files and folders through every sub directory created (more than 2 levels down) then you could create a recursion method to call and walk through every directory. It is slightly more complex and works in a hierarchical scenario however keep in mind it could cause performance decrease as more subfolders are contained within the root.