Active directory email list

  • Thread starter Thread starter Mike Harris
  • Start date Start date
M

Mike Harris

I would like to provide links to email addresses from my website via
ASP.net. Our email addresses are stored in Exchange 2000 so I would have to
query my AD database. Does anyone have any code samples detailing how this
can be accomplished? I would like for the website users to be able to click
on a letter of the alphabet, such as the letter "a" and have a list of all
email addresses that begin with "a" returned in a datagrid. Thanks,

Mike
 
Mike the small snippet should return the username and email address
if you play with you should get to what you want
Also make sure you import "Imports System.DirectoryServices"

Dim rootEntry As New DirectoryEntry("LDAP://yourdomain/DC=yourdomain,
DC=com, DC=au", "yourusernameforActivedirectory", "password")
Dim Mysearcher As New DirectorySearcher(rootEntry)
Mysearcher.PropertiesToLoad.Add("cn")
Mysearcher.PropertiesToLoad.Add("mail")
'searcher.PropertiesToLoad.AddRange(New String() {"cn", "mail"})
'would also work and saves you some code
Mysearcher.Filter = "(&(anr=yourusername)(objectCategory=person))"
Dim Myresults As SearchResultCollection
Myresults = Mysearcher.FindAll()
Dim result As SearchResult
For Each result In Myresults
Response.Write("name=" + result.Properties("cn")(0) + "<br>E-mail=" +
result.Properties("mail")(0) + "<br>")
Next

Hope that helps
Patrick
 

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

Back
Top