locked
Populate drop down list with names from Active Directory using ASP.NET(VB.NET) RRS feed

  • Question

  • User-1352183928 posted

    Hi,

    I'm fairly new to Active Directory and I am trying to populate drop down list with names from Active Directory using ASP.NET(VB.NET). I also want to know how to retrieve user's in AD their phone, address, etc. The last thing I would like to know how to do is find out the current user login who is on the web page.

     

    Thank you very much!

    Tuesday, February 21, 2006 10:54 AM

All replies

  • User-603216933 posted

    I need to do the same but am stumped! Please let me know if you find a solution.

    Thanks,

    Kurt

    Wednesday, February 22, 2006 9:19 AM
  • User-1668286398 posted

    Hey I had to do something similar. Create a drop down list name d1 and use the following code.

            Dim de As DirectoryEntry = New DirectoryEntry("LDAP://dc=mydomain,dc=com")
            Dim usr As String
            Dim oSearcher As DirectorySearcher = New DirectorySearcher(de)
            oSearcher.Sort.PropertyName = "cn"
            Dim oResults As SearchResultCollection
            Dim oResult As SearchResult
            oSearcher.PropertiesToLoad.Add("cn")
            oResults = oSearcher.FindAll
            For Each oResult In oResults
                usr = oResult.GetDirectoryEntry().Properties("cn").Value
                d1.Items.Add(usr)
            Next

    Put this code in the page load sub and you are ready to roll.

     

    Monday, March 6, 2006 3:09 AM
  • User-603216933 posted

    Just what I was looking for.

    Thanks,

    Kurt

    Monday, March 6, 2006 3:00 PM
  • User1354132231 posted
    This seems to come up so often I should put it in the FAQ.  You need to create a datasource manually and bind to the dropdown list (or grid, or whatever).  I have a sample on how to do this with some flexibility (like caching, etc):

    See the code I posted here for a function called 'FindUsers'.



    Wednesday, March 8, 2006 11:56 AM
  • User-603216933 posted

    I also need to populate a listbox, or whatever control, when using Windows Security (without Active Directory).

    Any suggestions?

    Thanks,

    Wednesday, March 8, 2006 6:40 PM
  • User1354132231 posted
    You want a list of the local users on the machine?  Try the WinNT provider - it is used for the local SAM.  You should find scripts for this on Technet and around the web as well.
    Monday, March 13, 2006 12:15 PM