I have the following code to list all the users in my AD tree and populate a treeview from it:
And i have the code to list all the users samAccountNames:
What i want to do is set the samAccountName value as the tag of corrensponding user node in the treeview
any help would be appreciated
VB.NET:
Sub FillActiveDirectoryTreeView(ByRef tvw As TreeView, ByVal TopLevelDirEntriesArray As DirectoryEntry)
Dim DirEntry As DirectoryEntry
Dim Nd As TreeNode
For Each DirEntry In TopLevelDirEntriesArray.Children
Nd = New TreeNode(DirEntry.Name.Remove(0, 3))
Nd.Tag = DirEntry
tvw.Nodes.Add(Nd)
FillADTreeNode(Nd)
Next
End Sub
Sub FillADTreeNode(ByRef ADNode As TreeNode)
Dim DirEntry As DirectoryEntry
Dim MainEntry As DirectoryEntry = CType(ADNode.Tag, DirectoryEntry)
Dim Nd As TreeNode
For Each DirEntry In MainEntry.Children
Nd = New TreeNode(DirEntry.Name.Remove(0, 3))
Nd.Tag = DirEntry
ADNode.Nodes.Add(Nd)
FillADTreeNode(Nd)
Nd.Tag = Nd.Text
Next
End Sub
And i have the code to list all the users samAccountNames:
VB.NET:
Dim de As DirectoryEntry = New DirectoryEntry("LDAP://OU=xxxxxxx,DC=xxxxxxxx,DC=Com")
Dim objSearcher As DirectorySearcher = New DirectorySearcher(de)
objSearcher.Filter = "(objectClass=User)"
Dim objresults As SearchResult
For Each objresults In objSearcher.FindAll()
objresults.GetDirectoryEntry().Properties("sAMAccountName").Value.ToString()
Next
What i want to do is set the samAccountName value as the tag of corrensponding user node in the treeview
any help would be appreciated