Active Directory List OU's
        Posted  
        
            by Stephen Murby
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Stephen Murby
        
        
        
        Published on 2010-05-25T15:39:13Z
        Indexed on 
            2010/05/25
            15:41 UTC
        
        
        Read the original article
        Hit count: 380
        
I have this code currently, string defaultNamingContext;
        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
        defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        rootDSE = new DirectoryEntry("LDAP://" + defaultNamingContext);
        //DirectoryEntry domain = new DirectoryEntry((string)"LDAP://" + defaultNamingContext);
        DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,"(objectCategory=Organizational-Unit)", 
                                 null, SearchScope.Subtree);
        MessageBox.Show(rootDSE.Path.ToString());
        try
        {
            SearchResultCollection collectedResult = ouSearch.FindAll();
            foreach (SearchResult temp in collectedResult)
            {
                comboBox1.Items.Add(temp.Properties["name"][0]);
                DirectoryEntry ou = temp.GetDirectoryEntry();
            }
        }
When i use the debugger i can see that rootDSE.Path is infact pointing to the right place, in this case "DC=g-t-p,DC=Local" but the directory searcher doesn't find any results. Can anyone help?
© Stack Overflow or respective owner