Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how Get parent OU of child ou in Active Directory using C#
how Get parent OU of child ou in Active Directory using C#
how Get parent OU of child ou in Active Directory using C#

how Get parent OU of child ou in Active Directory using C#
how Get parent OU of child ou in Active Directory using C#

how Get parent OU of child ou in Active Directory using C#
Posted

1 solution

You can use the Path property of your DirectoryEntry object.

DirectoryEntry user = null;
DirectoryEntry gcEntry = new DirectoryEntry("GC:");

IEnumerator ie = gcEntry.Children.GetEnumerator();

while (ie.MoveNext())
{

    gcEntry = (DirectoryEntry)ie.Current;

}

using (DirectorySearcher searcher = new DirectorySearcher(gcEntry))
{
   searcher.Filter = string.Format(ldapQueryString);
   SearchResult result = searcher.FindOne();
   string[] pathParts = user.Path.Split(new char[] { ',', ' ' });
}
 
Share this answer
 
v2
Comments
nimaaamin 21-Dec-13 0:24am    
Thank you for the response.
Please explain more
what "GC:"??????
Where should I enter my child ou of it to my parents back?
what ldapQueryString????????????????
Christopher Drake 23-Dec-13 8:46am    
The gc is the global catalog. You probably don't need it. You can initialize the directory searcher object using an empty constructor. The path will have the ou. Whatever ldap query you use to get your child object. If you already have the object, you don't need the query.
nimaaamin 26-Dec-13 2:07am    
Thank you! I am grateful!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900