Here is some nasty sample code to get you on your way:
private void button2_Click(object sender, System.EventArgs e) {
if (DialogResult.OK != this.folderBrowserDialog1.ShowDialog(this))
return;
string root = this.folderBrowserDialog1.SelectedPath;
TreeNode rootNode = new TreeNode(root);
this.treeView1.Nodes.Add(rootNode);
this.AddChildren(rootNode, root);
}
private void AddChildren(TreeNode node, string path) {
foreach (string subDir in Directory.GetDirectories(path)) {
TreeNode subDirNode = new TreeNode(subDir);
node.Nodes.Add(subDirNode);
this.AddChildren(subDirNode, subDir);
}
foreach (string file in Directory.GetFiles(path)) {
TreeNode fileNode = new TreeNode(file);
node.Nodes.Add(fileNode);
}
}
Note: folderBrowserDialog1 is a FolderBrowserDialog control on the form.
This class is only available in v1.1 of the framework, which means you need
to be using VS.NET 2003. If you don't have VS.NET 2003 you'll have to try
and figure out another way to select a folder, there are examples floating
around on the internet that you can search for.
John.