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
¤
di*****@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 ~~~
pc******@amerit ech.net
Microsoft MVP (Visual Basic)