Solved

Get the AD department field

Posted on 2011-02-22
2
1,446 Views
Last Modified: 2012-05-11
I can successfully pull out fields from an AD account but unable to get the 'department' field using System.DirectoryServices.AccountManagement for framework 3.5.

The object 'user' that's returned by UserPrincipal does not seem to have a property for this or one that I cannot find. Anyone have a solution instead of using the old System.DirectoryServices model?
using System.DirectoryServices.AccountManagement;

PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, "MyDomain", "DC=MyDomain,DC=com,DC=au");

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.SamAccountName, "aduser");

 lblInfo.Text = "<br>" + user.DisplayName.ToString();
 lblInfo.Text += "<br>" + user.EmailAddress.ToString();

Open in new window

0
Comment
Question by:chris_desborough
2 Comments
 
LVL 12

Accepted Solution

by:
geowrian earned 250 total points
ID: 34957459
0
 
LVL 1

Author Closing Comment

by:chris_desborough
ID: 34957701
Thanks geowrian - works great. Thanks for the tip.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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