More AD Query Questions - C# - 3.5 Framework

Discussion in 'ASP .Net' started by greg.hart@alpinebiomed.com, Apr 3, 2009.

  1. 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 />");


    }
     
    , Apr 3, 2009
    #1
    1. Advertising

  2. On 3 Apr., 23:48, wrote:
    > 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
     
    Alexey Smirnov, Apr 13, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anatoly Volodko
    Replies:
    1
    Views:
    2,126
    Mattias Sjögren
    Aug 14, 2003
  2. Charles A. Lackman
    Replies:
    1
    Views:
    1,401
    smith
    Dec 8, 2004
  3. Mark
    Replies:
    4
    Views:
    1,733
    Juan T. Llibre
    Nov 17, 2005
  4. Michael
    Replies:
    4
    Views:
    436
    Matt Hammond
    Jun 26, 2006
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    223
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page