Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:35:58+00:00 2026-05-28T16:35:58+00:00

I am using Visual Studio 2005 C#. I am trying to retrieve the list

  • 0

I am using Visual Studio 2005 C#.

I am trying to retrieve the list of users in my Active Directory and insert them into a DropDownList control.

May I know how do I pull out the users and how can I insert them into the DropDownList
control?


EDIT:

There are many parts of the functionality I would wish to complete.

Firstly is to list all users in a DropDownList, and having 2 checkboxes, User and Admin, and base on the role assigned to the user in the DDL, appropriate checkboxes will be checked.

Checking and unchecking of the role checkboxes will also assign/revoke the roles accordingly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:35:59+00:00Added an answer on May 28, 2026 at 4:35 pm

    If you’re on .NET 3.5 and up, you can use a PrincipalSearcher and a “query-by-example” principal to do your searching:

    // create your domain context
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
    // define a "query-by-example" principal - here, we search for all users
    UserPrincipal qbeUser = new UserPrincipal(ctx);
    
    // create your principal searcher passing in the QBE principal    
    PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
    
    // find all matches
    foreach(var found in srch.FindAll())
    {
        // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
    }
    

    If you haven’t already – absolutely read the MSDN article Managing Directory Security Principals in the .NET Framework 3.5 which shows nicely how to make the best use of the new features in System.DirectoryServices.AccountManagement

    This code could be rather slow – especially if you have a large AD, and a large number of users in your AD. But then again: is it really helpful to list thousands of users in a single drop down?? You might need to rethink your strategy there….

    Update: if you cannot use .NET 3.5, you’ll have to use the “legacy” DirectorySearcher class instead – something like this:

    // find your default naming context
    DirectoryEntry deRoot = new DirectoryEntry("LDAP://RootDSE");
    string defaultCtx = deRoot.Properties["defaultNamingContext"].Value.ToString();
    
    // define a directory searcher for your default context
    string searchRootLDAPPath = "LDAP://" + defaultCtx;
    DirectoryEntry defaultDE = new DirectoryEntry(searchRootLDAPPath);
    
    // define searcher - search through entire subtree, search for users 
    // (objectCategory=Person)           
    DirectorySearcher dsAllUsers = new DirectorySearcher(defaultDE);
    dsAllUsers.SearchScope = SearchScope.Subtree;
    dsAllUsers.Filter = "(objectCategory=Person)";
    
    // get the results
    SearchResultCollection result = dsAllUsers.FindAll();
    
    // count the user objects found
    int count = result.Count;
    

    As I mentioned – this will not perform very well on a large AD, and you might run into limits (like max. of 1’000 users returned) and other issues. You should maybe allow users to search for users, e.g. by their name or something – rather than listing out all your users (depending on the size of your AD).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a C/C++ static library using visual studio 2005. Since the
I'm trying to call the HttpServerUtuility.URLDecode function in C# using Visual Studio 2005, but
I was trying to compile our project in Visual Studio 2010 using the 2005
Using SQL Server 2005 and Visual Studio 2005, I'm trying to create a SSIS
Using Visual Studio 2005 As per the title; MSDN and google can't tell me,
Using Visual Studio 2005, I wrote a simple DLL in C that uses the
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I am using Visual Studio 2005 with Team Foundation Server. When I right click
I am using Visual Studio 2005 to make an install. The application has a
I am using Visual Studio 2005 and StarTeam 2008 (cross-platform client and VS integration).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.