Here this is my program
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecondWeekContinues
{
public partial class TreeViewDemo : Form
{
public TreeViewDemo()
{
InitializeComponent();
ListDirectory(,"D:\\"); //See i am getting error here
}
private void ListDirectory(TreeView treeView, string path)
{
treeView1.Nodes.Clear();
var stack = new Stack();
var rootDirectory = new DirectoryInfo(path);
var node = new TreeNode(rootDirectory.Name) { Tag = rootDirectory };
stack.Push(node);
while (stack.Count > 0)
{
var currentNode = stack.Pop();
var directoryInfo = (DirectoryInfo)currentNode.Tag;
foreach (var directory in directoryInfo.GetDirectories())
{
var childDirectoryNode = new TreeNode(directory.Name) { Tag = directory };
currentNode.Nodes.Add(childDirectoryNode);
stack.Push(childDirectoryNode);
}
foreach (var file in directoryInfo.GetFiles())
currentNode.Nodes.Add(new TreeNode(file.Name));
}
treeView1.Nodes.Add(node);
}
}
}
10 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Gnanavel SekarPosted Mar 13, 2017, 9:30 AM
Tapan PatelPosted Mar 16, 2017, 9:26 AM
Thennarasu NPosted Mar 16, 2017, 1:27 AM
Bryian TanPosted Mar 14, 2017, 1:24 AM
chetan AllipurPosted Mar 14, 2017, 12:33 AM
Marimuthu KaruppaiahPosted Mar 13, 2017, 9:56 AM
chetan AllipurPosted Mar 13, 2017, 9:13 AM
chetan AllipurPosted Mar 13, 2017, 9:09 AM
chetan AllipurPosted Mar 13, 2017, 9:04 AM
Gnanavel SekarPosted Mar 13, 2017, 9:02 AM