Probably this code should work. I didn't test it though.
public static void AddNodes(FlyTreeNodeCollection nodes, string directoryPath){
DirectoryInfo directory = new DirectoryInfo(Path.Combine(ROOT_FOLDER, directoryPath));
if (!directory.Exists) return;
DirectoryInfo[] subDirectories = directory.GetDirectories();
foreach (DirectoryInfo subDir in subDirectories)
{
FlyTreeNode ftn = new FlyTreeNode();
ftn.Text = HttpUtility.HtmlEncode(subDir.Name);
ftn.Value = subDir.Name;
ftn.NavigateUrl = subDir.FullName;
nodes.Add(ftn);
try
{
// do not set populate on demand for nodes that have no nested directories
ftn.PopulateNodesOnDemand = subDir.GetDirectories().Length > 0;
}
catch (Exception ex)
{
// add a child node that shows that there was an exception trying to get its child nodes
AddExceptionNode(ftn.ChildNodes, ex);
}
}
FileInfo[] files = directory.GetFiles();
foreach (FileInfo file in files)
{
FlyTreeNode ftn = new FlyTreeNode();
ftn.Text = HttpUtility.HtmlEncode(file.Name);
ftn.Value = file.Name;
ftn.NavigateUrl = file.FullName;
nodes.Add(ftn);
}
}