gowerman
asked on
AD connection get mail properties problem
Hi,
VB, VS 2010express,
Im trying to get email properties from AD, when I do
then everything is working but if I change filter="cn=username" then even if he find a record it's not taking email address
any reason why?
thanks for all advise
regards
VB, VS 2010express,
Im trying to get email properties from AD, when I do
Public Shared Sub ADconnection()
Dim oSearcher As New DirectorySearcher
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
Dim mCount As Integer
Dim mLDAPRecord, mLDAPemail, mLDAPFullname As String
Dim ResultFields() As String = {"securityEquals", "cn"}
Try
With oSearcher
.SearchRoot = New DirectoryEntry("LDAP://" & "domainserver" & _
"/dc=xxx,dc=local")
.PropertiesToLoad.AddRange(ResultFields)
.Filter = "sn=" & "*"
oResults = .FindAll()
End With
mCount = oResults.Count
If mCount > 0 Then
For Each oResult In oResults
mLDAPRecord = oResult.GetDirectoryEntry().Properties("cn").Value
mLDAPemail = oResult.GetDirectoryEntry().Properties("mail").Value
mLDAPFullname = oResult.GetDirectoryEntry().Properties("sn").Value
Next
End If
Catch e As Exception
MsgBox("Error is " & e.Message)
End Try
End Sub
then everything is working but if I change filter="cn=username" then even if he find a record it's not taking email address
any reason why?
thanks for all advise
regards
ASKER
i change as you said but still same. I checked several records they all contain that property as when I run the first one it takes all users emails
this attribute shouldn't be a multivalued attribute, but i've found some code
mLDAPemail = oResult.GetDirectoryEntry( ).Properti es("mail") (0).toStri ng()
mLDAPemail = oResult.GetDirectoryEntry( ).Properti es("mail") (0).Value
maybe can you try ...
mLDAPemail = oResult.GetDirectoryEntry(
mLDAPemail = oResult.GetDirectoryEntry(
maybe can you try ...
ASKER
when I tried this then I have index is out of range
ok so this is singlevalued, that's fine. Don't know why you encounter the issue, i'll try to investigate further.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thats works for me
Dim ResultFields() As String = {"securityEquals", "cn"}
I would change it to:
Dim ResultFields() As String = {"securityEquals", "cn", "mail"}
and maybe more to:
Dim ResultFields() As String = {"securityEquals", "cn", "mail", "sn"}