How to display all users from AD via c#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amrulloh

    #1

    How to display all users from AD via c#?

    I tried this code but it failed showing me the error "unknown error" and I think in this part findall() of my code.
    Code:
     public void User()
            {
                try
                {
                    DirectoryEntry entry = new DirectoryEntry("ldap://test.atb.dom");
                    entry.AuthenticationType = AuthenticationTypes.Secure;
    
                    DirectorySearcher desearch = new DirectorySearcher(entry);
                    desearch.Filter = "(&(objectClass=user))";
    
                    SearchResultCollection results = desearch.FindAll();
    
                    foreach (SearchResult srUser in results)
                    {
                        DirectoryEntry de = srUser.GetDirectoryEntry();
                        if (de.Username != null)
                            comboBox1.Items.Add(de.Username);
    
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
    Any idea how to display users into combobox or how to fix my problem?
    thanks
    Last edited by Curtis Rutland; Oct 19 '10, 02:31 PM. Reason: fixed code tag
Working...