Hi,
If you want to get the folder's files, you need to add some code in the AddNodeAndDescendents function, the border characters is the added code:
private TreeNode AddNodeAndDescendents(DirectoryInfo folder, TreeNode parentNode)
{
//Add the TreeNode, displaying the folder's name and storing the full path to the folder as the value...
string virtualFolderPath;
if (parentNode == null)
{
virtualFolderPath = VirtualImageRoot;
}
else
{
virtualFolderPath = parentNode.Value + folder.Name + "/";
}
TreeNode node = new TreeNode(folder.Name, virtualFolderPath);
//Recurse through this folder's subfolders
DirectoryInfo[] subFolders = folder.GetDirectories();
foreach (DirectoryInfo subFolder in subFolders)
{
TreeNode child = AddNodeAndDescendents(subFolder, node);
foreach (FileInfo file in subFolder.GetFiles())
{
int index = file.FullName.LastIndexOf("\\");
string strname = file.FullName.Substring(index + 1);
string[] name = strname.Split('.');
TreeNode tn = new TreeNode(name[0], file.FullName);
child.ChildNodes.Add(tn);
}
node.ChildNodes.Add(child);
}
//Return the new TreeNode
return node;
}
Then you can open the file in the treeview's SelectedNodeChanged event:
protected void DirectoryTree_SelectedNodeChanged(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(this.DirectoryTree.SelectedNode.Value);
}
Hope it helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Yours sincerely,
Amanda Wang
Microsoft Online Community Support