locked
Problem accessing DirectoryEntry.Parent RRS feed

  • Question

  • User140301456 posted

    I am using the below method to retrieve a directory entry, but am unable to access the parent, which is null. How can I retrieve the directoryentry for the parent.

     Thanks in advance.

    public static DirectoryEntry UserFromNTAccount(DirectoryEntry searchRoot, string ntUser)
            {
                DirectorySearcher searcher = new DirectorySearcher(searchRoot);
                searcher.SizeLimit = 25;
                searcher.SearchScope = SearchScope.Subtree;
                   

                string ldapSearchFormat = "(sAMAccountName={0})";
                string ldapQuery = string.Format(ldapSearchFormat, ntUser);
                searcher.Filter = ldapQuery;

                try
                {
                   
                    SearchResult result = searcher.FindOne();
                   
                    searchRoot.Close();

                    if (result != null)
                    {
                        return result.GetDirectoryEntry();
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine("An exception occured: " + e.ToString());
                }

                return null;
            }

     
    Monday, May 18, 2009 5:21 PM

All replies

  • User231262039 posted

    Hi Compwiz,

    First thing you have to do in getting Directory Entry is to know the LDAP Structure of your domain. You have to use LDAP browser in order to see the LDAP structure. Some example of LDAP Browsers are JXploer, LDAPSoft and Softerra LDAP.

    Thursday, May 21, 2009 9:04 PM