getting user data from Active Directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dinçer

    #1

    getting user data from Active Directory

    Hi,

    I am trying to get user data (email data actually) from Active Directory.
    What I exactly want to do is, getting the email address according to
    username from the domain.
    For example, when I enter my username DINCERM, it should give me
    dincerm@domain. com as result.

    When I do this:
    ===
    DirectoryEntry entry = new DirectoryEntry( LDAP://DENIZ);

    DirectorySearch er searcher = new DirectorySearch er(entry);

    searcher.Filter = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";

    ===

    Then I can get all users with an email address available. But how will I be
    able to filter it according to the username?

    Thank you..







  • Cor Ligthert

    #2
    Re: getting user data from Active Directory

    Dincer,

    Did you try this message in the newsgroup.
    microsoft.publi c.dotnet.langua ges.csharp

    Probably you have there a better change on an answer.

    Cor


    Comment

    • Dinçer

      #3
      Re: getting user data from Active Directory

      I will.. Thank you..

      "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
      news:eZbenPBjEH A.712@TK2MSFTNG P09.phx.gbl...[color=blue]
      > Dincer,
      >
      > Did you try this message in the newsgroup.
      > microsoft.publi c.dotnet.langua ges.csharp
      >
      > Probably you have there a better change on an answer.
      >
      > Cor
      >
      >[/color]


      Comment

      • Paul Clement

        #4
        Re: getting user data from Active Directory

        On Fri, 27 Aug 2004 11:14:49 +0300, "Dinçer" <dincer"AT"o2.p l> wrote:

        ¤ Hi,
        ¤
        ¤ I am trying to get user data (email data actually) from Active Directory.
        ¤ What I exactly want to do is, getting the email address according to
        ¤ username from the domain.
        ¤ For example, when I enter my username DINCERM, it should give me
        ¤ dincerm@domain. com as result.
        ¤
        ¤ When I do this:
        ¤ ===
        ¤ DirectoryEntry entry = new DirectoryEntry( LDAP://DENIZ);
        ¤
        ¤ DirectorySearch er searcher = new DirectorySearch er(entry);
        ¤
        ¤ searcher.Filter = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";
        ¤
        ¤ ===
        ¤
        ¤ Then I can get all users with an email address available. But how will I be
        ¤ able to filter it according to the username?
        ¤

        See if the following works for you:

        Public Function GetUserInfo(ByV al UserID As String)

        Dim RootDSE As New DirectoryServic es.DirectoryEnt ry("LDAP://RootDSE")
        Dim DomainDN As String = RootDSE.Propert ies("DefaultNam ingContext").Va lue
        Dim ADEntry As New DirectoryServic es.DirectoryEnt ry("LDAP://" & DomainDN)
        Dim ADSearch As New System.Director yServices.Direc torySearcher(AD Entry)

        Dim ADSearchResult As System.Director yServices.Searc hResult
        ADSearch.Filter = ("(samAccountNa me=" & UserID & ")")
        ADSearch.Search Scope = SearchScope.Sub tree
        Dim UserFound As SearchResult = ADSearch.FindOn e()
        If Not IsNothing(UserF ound) Then
        Console.WriteLi ne(UserFound.Ge tDirectoryEntry ().Properties.I tem("mail").Val ue)
        End If

        End Function


        Paul ~~~ pclement@amerit ech.net
        Microsoft MVP (Visual Basic)

        Comment

        • Paul Clement

          #5
          Re: getting user data from Active Directory

          On Fri, 27 Aug 2004 11:14:49 +0300, "Dinçer" <dincer"AT"o2.p l> wrote:

          ¤ Hi,
          ¤
          ¤ I am trying to get user data (email data actually) from Active Directory.
          ¤ What I exactly want to do is, getting the email address according to
          ¤ username from the domain.
          ¤ For example, when I enter my username DINCERM, it should give me
          ¤ dincerm@domain. com as result.
          ¤
          ¤ When I do this:
          ¤ ===
          ¤ DirectoryEntry entry = new DirectoryEntry( LDAP://DENIZ);
          ¤
          ¤ DirectorySearch er searcher = new DirectorySearch er(entry);
          ¤
          ¤ searcher.Filter = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";
          ¤
          ¤ ===
          ¤
          ¤ Then I can get all users with an email address available. But how will I be
          ¤ able to filter it according to the username?
          ¤

          See if the following works for you:

          Public Function GetUserInfo(ByV al UserID As String)

          Dim RootDSE As New DirectoryServic es.DirectoryEnt ry("LDAP://RootDSE")
          Dim DomainDN As String = RootDSE.Propert ies("DefaultNam ingContext").Va lue
          Dim ADEntry As New DirectoryServic es.DirectoryEnt ry("LDAP://" & DomainDN)
          Dim ADSearch As New System.Director yServices.Direc torySearcher(AD Entry)

          Dim ADSearchResult As System.Director yServices.Searc hResult
          ADSearch.Filter = ("(samAccountNa me=" & UserID & ")")
          ADSearch.Search Scope = SearchScope.Sub tree
          Dim UserFound As SearchResult = ADSearch.FindOn e()
          If Not IsNothing(UserF ound) Then
          Console.WriteLi ne(UserFound.Ge tDirectoryEntry ().Properties.I tem("mail").Val ue)
          End If

          End Function


          Paul ~~~ pclement@amerit ech.net
          Microsoft MVP (Visual Basic)

          Comment

          • Marc Scheuner [MVP ADSI]

            #6
            Re: getting user data from Active Directory

            >For example, when I enter my username DINCERM, it should give me[color=blue]
            >dincerm@domain .com as result.
            >
            >DirectoryEnt ry entry = new DirectoryEntry( LDAP://DENIZ);
            >DirectorySearc her searcher = new DirectorySearch er(entry);
            >searcher.Filte r = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";[/color]

            You'll need to add (samACcountName =DINCERM) to your filter, and also,
            you'll need to specify which attributes you want to retrieve:

            DirectorySearch er searcher = new DirectorySearch er("LDAP://DENIZ");

            searcher.Filter = "
            (&(objectClass= user)(objectCat egory=person)(s amAccountName=D INCERM))";

            // add the mail property to the list of props to retrieve
            // you can add any others you might be interested in, too!
            searcher.Proper tiesToLoad.Add( "mail");

            DirectoryEntry deUser = searcher.FindOn e();
            if(deUser != null)
            {
            Console.WriteLi ne("Your e-mail is: " +
            deUser.Properti es["mail"].Value.ToString ();
            }

            Marc

            =============== =============== =============== =============== ====
            Marc Scheuner May The Source Be With You!
            Bern, Switzerland m.scheuner(at)i nova.ch

            Comment

            Working...