More AD Query Questions - C# - 3.5 Framework

G

greg.hart

Hello all,

I am using the code below to query data from AD. Everything working
well, but I wanted to get some additional data like: title, dept,
pager, etc. These don't seem to appear as properties of
UserPrincipal. Is it possible to retrieve them or do I need to use
the DirectorySearcher class from the 2.0 framework to retrieve these
values.

Thanks.

PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
<Domain>,<UserName>,<Password>);
UserPrincipal u = new UserPrincipal(ctx);
u.Enabled = true;
u.Name = "*";
u.VoiceTelephoneNumber = "*";


PrincipalSearcher ps = new PrincipalSearcher(u);
PrincipalSearchResult<Principal> fr = ps.FindAll();


foreach (UserPrincipal usr in fr)
{


Response.Write(usr.DisplayName + "&nbsp;&nbsp;" +
usr.VoiceTelephoneNumber + "<br />");


}
 
G

Guest

Hello all,

I am using the code below to query data from AD.  Everything working
well, but I wanted to get some additional data like: title, dept,
pager, etc.  These don't seem to appear as properties of
UserPrincipal.  Is it possible to retrieve them or do I need to use
the DirectorySearcher class from the 2.0 framework to retrieve these
values.

Thanks.

 PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
<Domain>,<UserName>,<Password>);
            UserPrincipal u = new UserPrincipal(ctx);
            u.Enabled = true;
            u.Name = "*";
            u.VoiceTelephoneNumber = "*";

            PrincipalSearcher ps = new PrincipalSearcher(u);
            PrincipalSearchResult<Principal> fr = ps.FindAll();

            foreach (UserPrincipal usr in fr)
            {

                Response.Write(usr.DisplayName + "&nbsp;&nbsp;" +
usr.VoiceTelephoneNumber + "<br />");

            }

Hi Greg,

UserPrincipal has following properties:
http://msdn.microsoft.com/en-us/lib...countmanagement.userprincipal_properties.aspx

if you need more, use DirectorySearcher, you will find many examples
on MSDN

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top