Posted: 7/25/2011
So i am trying to list out the Sub-OU inside an OU but i am having problem doing it as it lists everything. I only want a sub OU inside a specified (hard coded) OU.
could someone please point me to the right direction?
[code]
public void getOU() { string defaultNamingContext; //TODO 0 - Acquire and display the available OU's DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"); defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString(); DirectoryEntry entryToQuery = new DirectoryEntry("LDAP://" + defaultNamingContext); //MessageBox.Show(entryToQuery.Path.ToString()); DirectorySearcher ouSearch = new DirectorySearcher(entryToQuery.Path); ouSearch.Filter = "(objectClass=organizationalUnit)"; ouSearch.SearchScope = SearchScope.Subtree; ouSearch.PropertiesToLoad.Add("name"); SearchResultCollection allOUS = ouSearch.FindAll(); foreach (SearchResult oneResult in allOUS) { //comboBox1.Items.Add(oneResult.ToString()); lstOU.Items.Add(oneResult.Properties["name"][0].ToString()); }}
[/code]
i am calling the function from my page load event and this is the asp form.
<div> <asp:DropDownList ID="lstOU" runat="server"> </asp:DropDownList> </div>
thanks