I have an OU called "Sites"
Do you know the full LDAP path for that OU as well??
It would have to be something like:
LDAP://OU=Sites,OU=SomeOtherOU,dc=YourCompany,dc=com
I want to click a button called btn1 and I want to retrieve all the Sites
under this OU into a dropdownlist Called dropdownlist1. I want to do this
using LDAP. I'm working with a asp.net webform.
Using that full LDAP path for your main "Sites" OU, you can easily set
up a DirectorySearcher to retrieve all the sub-OU's under that OU. Do
you want to get just the immediate children, or do you want to recurse
down through the OU hierarchy?
This assumes you want only the immediate children - and only of type
"organizationalUnit":
DirectoryEntry deMySites = new
DirectoryEntry("LDAP://OU=Sites,OU=SomeOtherOU,dc=YourCompany,dc=com");
DirectorySearcher dsSubOUs = new DirectorySearcher(deMySites);
// search only immediate children - use SearchScope.Subtree for all
// immediate children and subsequent grandchildren etc.
dsSubOUs.SearchScope = SearchScope.OneLevel;
// set the filter - we're only interested in OU's
dsSubOUs.Filter = "(objectClass=organizationalUnit)";
// set up what attributes to load - specify whatever attributes
// you are interested in as results in your search
dsSubOUs.PropertiesToLoad.Add("name");
dsSubOUs.PropertiesToLoad.Add("cn");
dsSubOUs.PropertiesToLoad.Add("dateCreated");
// search for all matching OU's
foreach(SearchResult oResult in dsSubOUs.FindAll())
{
// add the "name" attribute of the result to your combo box
if(oResult.Properties.Contains("name"))
{
childOUsComboBox.Items.Add(oResult.Properties["name"][0].ToString();
}
}
Hope this helps
Marc