Hello, I am populating the root nodes of the treenode1 via the formload() function, I guess you could say they are hard coded. After that I want to select a root node (which will be a domain) and enumerate the OUs of that domain and then make the outputted (via the code below) sub nodes of the root node (domain) that is already listed. The function below makes the output, root nodes under the formload() created root nodes instead of subnodes under the formload() created root nodes, how can I make them subnodes of the original formload() root nodes? Sorry if this is written in a confusing manner, I've tried to reread it and make it less confusing amidst my own confusion.
private void searchForOus(string ouPath)
{
DirectoryEntry ADentry = new DirectoryEntry(ouPath, @"domain\\user", "password", AuthenticationTypes.Secure);
DirectorySearcher Searcher = new DirectorySearcher(ADentry);
Searcher.Filter = ("(objectClass=organizationalUnit)");
foreach (DirectoryEntry entry in Searcher.SearchRoot.Children)
{
Console.WriteLine(entry.Path);
if (entry.Path == "LDAP://OU=Core Member Servers,dc=XXX,dc=XXX,dc=XX,dc=XXX")
{
if (ShouldAddNode(entry.SchemaClassName))
{
treeView1.Nodes.Add(GetChildNode(entry));
}
}
}
private TreeNode GetChildNode(DirectoryEntry entry)
{
TreeNode node = new TreeNode(entry.Name.Substring(entry.Name.IndexOf('=') + 1));
foreach (DirectoryEntry childEntry in entry.Children)
{
if (ShouldAddNode(childEntry.SchemaClassName))
{
node.Nodes.Add(GetChildNode(childEntry));
}
}
return node;
}
private bool ShouldAddNode(string schemaClass)
{
bool returnValue = false;
if (schemaClass == "organizationalUnit")
{
returnValue = true;
}
return returnValue;
}