Unable to return active directory email field

J

JC

Hello.
I am 100% stumped by this and am very needy of a fix.

Please help me figure out why this code does not work-
I can access active directory information but can not return email address.
Here's the code---

Dim Root As New DirectoryEntry("LDAP://dc=dcomp1,dc=net")
Dim Searcher As New DirectorySearcher(Root)
With Searcher
..Filter = "(sAMAccountName=" & Environment.UserName & ")"
..SearchScope = SearchScope.Subtree
..PropertiesToLoad.Add("mail")
End With
Dim Result As SearchResult = Searcher.FindOne
Dim EMailAddress As String
If Not Result Is Nothing Then
EMailAddress = Result.GetDirectoryEntry.Properties("mail").Value
End If
Return EMailAddress

I keep getting "EMailAddress=nothing"

PLEASE help me figure this out.
Jeff
 
J

JC

I've since found that we store our e-mail in exchange only, not AD.
We'll be converting in 3 weeks so then I'll be able to get it. So now
the question is this:
What differences are there in connecting to Exchange and AD. I
thought this LDAP code would work for Exchange also, but I seem to
always hit AD. Could the exchange server also be a BDC and thus is
why I get AD info when I use LDAP?
Thanks for any help.
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top