Improve company productivity with a Business Account.Sign Up


Active Directory - basics to pull up user info

Posted on 2007-11-20
Medium Priority
Last Modified: 2008-02-01
Hello Experts,

I know a bit about programming, but I know basically nothing about active directory.  I've tried looking this up online, but haven't had any success.  Could someone post a snippet of code that would lets say display all users?

1 Comment

Accepted Solution

DavidTMoore earned 2000 total points
ID: 20322886
This might not be exactly what you are looking for, but these are the methods I use to interact with active directory, take a look and maybe they can give you a better understanding of how some of this works.
public static DirectoryEntry GetDirectoryEntry()
        DirectoryEntry de = new DirectoryEntry("LDAP://19dc01", "USERNAME", "PASSWORD");
        return de;
    public bool UserExists(string username)
        DirectoryEntry de = GetDirectoryEntry();
        DirectorySearcher deSearch = new DirectorySearcher();
        deSearch.SearchRoot = de;
        deSearch.Filter = "(&(objectClass=user) (cn=" + username + "))";
        SearchResultCollection results = deSearch.FindAll();
        return results.Count > 0;
    public String GetProperty(String userAccount, String propertyName)
        DirectoryEntry entry = GetDirectoryEntry();
        String account = userAccount.Replace(@"DOMAIN\", "");
            DirectorySearcher search = new DirectorySearcher(entry);
            search.Filter = "(SAMAccountName=" + account + ")";
            SearchResult result = search.FindOne();
            if (result != null)
                return result.Properties[propertyName][0].ToString();
                return "Unknown User";
        catch (Exception ex)
            string debug = ex.Message;
            return "";

Open in new window


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question