Loading ...

listing active directory Sub OU in an OU

Who is online?  0 guests and 1 members
home  »  forums   »  asp.net topics   »  data access   » listing active directory Sub OU in an OU

listing active directory Sub OU in an OU

Posts under the topic: listing active directory Sub OU in an OU

Posted: 7/25/2011

Lurker 30  points  Lurker
  • Joined on: 6/1/2011
  • Posts: 6

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


Page 1 of 1 (1 items)