September 20th, 2011, 10:48 AM
LDAP-query with C#
I'm writing a c#-application that will fetch data from a LDAP-catalog. I use the class System.DirectoryServices.DirectorySearcher and the method .FindAll() for
the searching. The class is instanciated by the constructor that takes DirectoryEntry Root as inparameter. Before the searching I set the property .Filter to a LDAP-searchstring, for example:
(&(objectclass=OrganizationalUnit)(ou=IT Application)) when searching for a unit named "IT Application" or
(&(objectClass=Person)(name=Göran)) when searching for a person named "Göran"
Now I want to make a query that returns all persons who belongs to a special unit in the organization. I've been told by an LDAP expert that this should be done in two steps:
1. With the SearchBase: c=SE and the filter: (&(objectClass=OrganizationalUnit)(ou=IT Application))
2. With the SearchBase set to the result from the first step and the filter: (objectClass=organizationalPerson)
The first searching performs well but I don't know how to do the second. How can I use the result from step 1 as SearchBase for step 2? What is a Searchbase?
Is there a property somewhere called SearchBase that I Should set? I can't find such a proprty anywhere.
I'll be glad if someone on this forum could help me and perhaps give me a coding example.