Last post May 10, 2012 06:55 PM by gww
May 10, 2012 03:14 AM|varunpals|LINK
I am stuck in a situation. I am not able to find the solution, so want your help.
Please see the following code
DirectoryEntry objdir = new DirectoryEntry("LDAP://server",username,password);
Now the requirement is that i need to find the existence of another DirectoryEntry in the above DirectoryEntry. Above DirectoryEntry is of type Organisation. Inside it i have to look for another DirectoryEntry of type OrganisationalUnit.
One way to achieve this is as following:-
objdir.Children.find(name); But in this case if there is no directoryentry of such type it straight away gives me exception. so i can't put this statement in If block.
Other way which i have followed is as below:
IEnumerator obj = objdir.Children.GetEnumerator();
the above approach is working fine, but it doesnot seems to be efficient to me.
Is there anyother way of achieving the above. Please let me know if i am not able to explain the senario properly.
May 10, 2012 06:44 AM|kushal.dwivedi|LINK
You can use DirectorySercher to search for another object and specify the SearchRoot as the objdir object.
May 10, 2012 06:55 PM|gww|LINK
When you setup your searcher you should be able to add the OU you want filter your results from if you want to search from the root.
Also, if you already know the level you want to begin your search from just add that to your ldap string when you declare your DirectoryEntry
DirectoryEntry objdir = new DirectoryEntry("LDAP://server/OU=, OU=,DC=,DC=",username,password);
and just use a filter to return only Organizational Units.