Hi how I want to know the directory info of the current selected node of treeview, so that I can add Folder to the specified (selected node) path?
Like If i have Tree
Root
=>Child
Root1
=>Child1
So when i select Root and Add folder folder should be added to root as well as same name folder should be added to the directory where the Root folder exists.
Check this:
private void btnAddFolder_Click(object sender, EventArgs e)
{
if (treeView1.SelectedNode != null)
{
TreeNode fileNode = new TreeNode();
fileNode.Text = txtFileName.Text;
treeView1.SelectedNode.Nodes.Add(fileNode);
string rootPath = treeView1.SelectedNode.Text; //here is your root path change it if it's wrong
Directory.CreateDirectory(rootPath + "\\" + txtFileName.Text);
// File.Create(rootPath + "\\" + txtFileName.Text); //if you want create a file instead of direcroty use this
}
}
PS: I assume you are typing your Directory or fileName into Textbox and Treenode texts contains your Directory path,i don't know how you configure your treeview.