On Fri, 27 Aug 2004 11:14:49 +0300, "Dinçer" <dincer"AT"o2.pl> 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);
¤
¤ DirectorySearcher searcher = new DirectorySearcher(entry);
¤
¤ searcher.Filter = " (&(objectClass=user)(objectCategory=person)(mail=* ))";
¤
¤ ===
¤
¤ 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(ByVal UserID As String)
Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry )
Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
Console.WriteLine(UserFound.GetDirectoryEntry().Pr operties.Item("mail").Value)
End If
End Function
Paul ~~~
pc******@ameritech.net
Microsoft MVP (Visual Basic)