More AD Query Questions - C# - 3.5 Framework

  • Thread starter Thread starter greg.hart
  • Start date Start date
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 />");


}
 
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
 
Back
Top