This below code works perfectly in vb 2005 but can't work in .net 1.1.
Private Function GetActiveDirUserDetails(ByVal useame As String) As String
Dim dirEntry As System.DirectoryServices.DirectoryEntry
Dim dirSearcher As System.DirectoryServices.DirectorySearcher
Try
dirEntry = New System.DirectoryServices.DirectoryEntry("LDAP://123.45.67.89:101/DC=mydomain,DC=com")
dirSearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)
dirSearcher.Filter = "(samAccountName=" & useame & ")"
Dim sr As DirectoryServices.SearchResult = dirSearcher.FindOne()
If sr Is Nothing Then
Retu False
End If
Dim de As System.DirectoryServices.DirectoryEntry = sr.GetDirectoryEntry()
'Dim firstname = de.Properties("GivenName").Value.ToString()
'Dim lastname = de.Properties("sn").Value.ToString()
'Dim fullname = de.Properties("DisplayName").Value.ToString()
Dim ObjFirstName As String = ""
Dim ObjLastName As String = String.Empty
Dim ObjEmail As String = ""
Try
ObjEmail = de.Properties("mail").Value.ToString()
ObjFirstName = de.Properties("GivenName").Value.ToString()
ObjLastName = de.Properties("sn").Value.ToString()
Catch ex As Exception
ObjFirstName = de.Properties("DisplayName").Value.ToString()
End Try
MsgBox(ObjFirstName + ObjLastName + ObjEmail)
Retu ObjFirstName
Retu ObjLastName
Retu ObjEmail
Catch ex As Exception ' retu false if exception occurs
Retu ex.Message
MsgBox(ex.Message)
End Try
End Function
When I press the button, it shows nothing. I am trying to get AD attributes here. Anybody can help?
