Chris Smith
Chris Smith

Reputation: 18712

Getting the display name from a domain \ alias combo

Apologies for not knowing the right way to phrase this question.

Given a domain name and an alias, for example CONTOSO\steveh how can I get the friendly display name for that alias? For example, in Outlook email sent to CONTOSO\steveh appears as 'Steve Holt'?

Upvotes: 2

Views: 2408

Answers (2)

Abhijeet Patel
Abhijeet Patel

Reputation: 6878

If you are using .net 3.5, add references to System.DirectoryServices and System.DirectoryServices.AccountManagement and try this:

        PrincipalContext c = new PrincipalContext(ContextType.Domain,"CONTOSO");
        UserPrincipal principal = UserPrincipal.FindByIdentity(c,"steveh");
        Console.WriteLine(principal.DisplayName);

I can't verify if it works for a domain since I'm running on a standalone machine but it should help you get started.

Upvotes: 6

Quintin Robinson
Quintin Robinson

Reputation: 82355

You can query ActiveDirectory through LDAP I recommend taking a look at this question which has some basic information. You should be able to get a general direction from there.

Upvotes: 0

Related Questions