Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

LDAP, ASP.NET, and VB. Can't populate dropdownlist with email addresses from exchange server.

Posted on 2006-10-23
6
Medium Priority
?
280 Views
Last Modified: 2012-06-21
I have tried several examples but can't seem to get the right sequence of pieces of code to make it happen. Any suggestions on how to do this.
0
Comment
Question by:wrwiii12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:bigphuckinglizard
ID: 17789830
Converted from c# so may be a bit funky, but try this... you also need to make sure you have a reference to System.DirectoryServices in your project.

               Dim LDAPConnection As New DirectoryEntry("LDAP://domain/OU=yourou,DC=domain,DC=tld", ConfigurationManager.AppSettings("LDAPUsername"), ConfigurationManager.AppSettings("LDAPPassword"))
                Try
                    Dim Searcher As New DirectorySearcher(LDAPConnection)
                    Searcher.Filter = "(objectclass=user)"
                    Searcher.PropertiesToLoad.Add("mail")
                    Dim results  as SearchResultCollection = Searcher.FindAll()
                    For Each (result as SearchResult in results) {
                        Dim email as String= LDAPConnection.Properties("mail")[0].ToString()
                        dropdownlist1.items.add(new ListItem(email))
                    Next
                Finally
                    LDAPConnection.Close() //very bad things happen if connections to ad are left open!!!
                End Try
0
 
LVL 4

Author Comment

by:wrwiii12
ID: 17791237
Almost there! (I think)
Name 'result' is not declared.

I know what the domain is, but what are the other parameters OU, DC, and DC.
If my domain is called "ecc.dept.local", how should the string look?
0
 
LVL 4

Author Comment

by:wrwiii12
ID: 17791362
Here is the revised code that at least compiles. It runs but throws and exception
at the LDAPConnection.Properties line:
Index was out of range. Must be non-negative and less than the size of the collection.


Dim LDAPConnection As New DirectoryEntry("LDAP://eccdept.local",
ConfigurationManager.AppSettings("LDAPUsername"),
ConfigurationManager.AppSettings("LDAPPassword"))
        Try
            Dim Searcher As New DirectorySearcher(LDAPConnection)
            Searcher.Filter = "(objectclass=user)"
            Searcher.PropertiesToLoad.Add("mail")
            Dim result As SearchResult
            Dim results As SearchResultCollection = Searcher.FindAll()
            For Each result In results
                Dim email As String  <--(seperated it for clarity on my part) -->
                email = LDAPConnection.Properties("mail")(0).ToString()  <-- line it errors on -->
                DropDownList1.Items.Add(New ListItem(email))
            Next
        Finally
            LDAPConnection.Close() '//very bad things happen if connections to ad are left open!!!
        End Try
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 6

Expert Comment

by:bigphuckinglizard
ID: 17793884
you need to know the netbios name of your domain as well, it should be

Dim LDAPConnection As New DirectoryEntry("LDAP://NETBIOSNAME/dc=eccdept,dc=local", username, password)

and i think i've found that vb needs an ienumerator in the loop:

            For Each result In results
                Dim email As String  <--(seperated it for clarity on my part) -->
                Dim i As IEnumerator = LDAPConnection.Properties("mail").GetEnumerator()                  
                While i.MoveNext
                        DropDownList1.Items.Add(i.Current.ToString())
                  End While
            Next
0
 
LVL 4

Author Comment

by:wrwiii12
ID: 17795680
it executes the results.count which the mouse tooltip says that there are 328 in count
it passes on through the Dim i as IENumerator and starts to cycle through the while i.movenext
it never drops inside the while loop
0
 
LVL 6

Accepted Solution

by:
bigphuckinglizard earned 800 total points
ID: 17796045
i've loaded up vb and got it sussed

Dim LDAPConnection As New DirectoryEntry("LDAP://NETBIOSNAME/dc=eccdept,dc=local", username, password)

        Try
            Dim Searcher As New DirectorySearcher(LDAPConnection)
            Searcher.Filter = "(objectclass=user)"
            Searcher.PropertiesToLoad.Add("mail")
            Dim result As SearchResult
            Dim results As SearchResultCollection = Searcher.FindAll()
            For Each result In results
                If result.Properties.Contains("mail") Then
                    DropDownList1.Items.Add(result.Properties("mail")(0).ToString())
                End If
            Next
        Finally
            LDAPConnection.Close() '//very bad things happen if connections to ad are left open!!!
        End Try
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question