Saturday, September 22, 2012

LDAP Path Extracter

Lightweight Directory Access Protocol provides secure way of accessing distributed directory information services over wire.In windows world LDAP serves as a way to access active directory via Net code.

Requirement of dealing with security,user,usergroups requires an interface between Net and Active for particular OU(Organization unit) .This sometimes require LDAP path to specific object.Deriving LDAP path manually requires to evaluate the whole hierarchy and frame the accurate path,which is time consuming and I guess the whole point of being developer is hate doing manual work and write code instead.

Check out the code-

using (DirectoryEntry dir = new DirectoryEntry("LDAP://OU=ORGANI1,OU=USER_DEVENV,DC=aloha,DC=net", "<domain>\\<UserName>", "<Password>"))

foreach (DirectoryEntry child in dir.Children)

string childPath = child.Path.ToString();






This code will fetch the LDAP path for all the childern for the particular parent where LDAP path is pointing to. If you are unsure of OU give the root level LDAP path like-


This will fetch the all the LDAP at root level and then just copy the LDAP required and reexecute the code with new LDAP until you locate the desired object.Got it! again manual steps so this can be automated by adding event and calling the event for action and send in the new LDAP path and tree can be easily used for this and I guess code for this is too easy to be mentioned here.

No comments:

Post a Comment