Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
What classes are necessary - depends on the task. To list directories and files, no additional classes are needed. The code could be something like this:
treeView1.Items.Clear();
GetFiles("C:/Windows/Microsoft.NET", null);
private void GetFiles(string path, TreeViewItem parent)
{
var node = new TreeViewItem() { Header = System.IO.Path.GetFileName(path) };
if (parent == null)
{
treeView1.Items.Add(node);
}
else
{
parent.Items.Add(node);
}
var attr = System.IO.File.GetAttributes(path);
if (attr.HasFlag(System.IO.FileAttributes.Directory))
{
var directories = System.IO.Directory.GetDirectories(path);
foreach (var dir in directories)
{
GetFiles(dir, node);
}
var files = System.IO.Directory.GetFiles(path);
foreach (var file in files)
{
node.Items.Add(System.IO.Path.GetFileName(file));
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question