User1901044945 posted
Hi there, im having troubles getting the mail property when i make a search of users based on their first name, i think that on the search results there is a user that doesn't have an email address on the AD.
What i want to ask you is how can I filter my search to make that the results brings me only the active users of the AD and how do i filter that search results so i can take out only the ones who has an email address asociated.
Dim de As DirectoryEntry =
New DirectoryEntry(adPath)
Dim ds As DirectorySearcher =
New DirectorySearcher(de)
ds.Filter =
"(&(&(objectClass=user)(objectCategory=person))((name=" & txt_nombre.Text &
"*)))"
ds.PropertiesToLoad.Add(
"displayName")
ds.PropertiesToLoad.Add(
"mail")
Dim sr As SearchResult =
Nothing
Dim src As SearchResultCollection = ds.FindAll
//This is the code im using that is blowing-up
For Each sr
In src
If sr.Properties("mail")(0)
Then //This Filter is what i dont know how to make it work
lbl_msg.Text = sr.Properties(
"mail")(0) //Here is where the aplication stops on a user with out an email asociated.
'Ckl_contactos2.Items.Add(New ListItem((sr.Properties("mail")(0))))
End If
Next sr
thanks for your Help and sorry for me Typing and grammar.