locked
Rretrieve AD search result in a dataview ! RRS feed

  • Question

  • User528608107 posted

    Hello guys,

    I need to make a page that search the active directory just like the MS Outlook search. so I need to get all UserNames from AD and bind it all to a datalist or a dropdownlist ! how can I retrieve the result in a dataview and bindi it ?



    Your immediate response is highly appreciated.

    Thanks


    Sunday, January 3, 2010 1:33 AM

All replies

  • User-1395461066 posted

    You can use webservice for this type of search.


    so that it can search runtime.

    thnx

    Sunday, January 3, 2010 2:33 AM
  • User528608107 posted

    its not about the run time search its all about how to retrieve the data from AD and HOW TO BIND IT TO A DATALIST ! I cant get it as a dataview or a dataset ! all what I'm able to do so far is to get it through a DirectorySearcher object and do a findall() search then make for each loop to get the results .

    Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://<domain name here>", <user here>,<password here>)
            Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
            Dim oresult As SearchResultCollection
            Dim result As SearchResult
    
            osearcher.Filter = "(&(objectCategory=person))" ' search filter
            osearcher.PropertiesToLoad.Add("cn") ' username
            'osearcher.PropertiesToLoad.Add("name") ' full name
            'osearcher.PropertiesToLoad.Add("givenname") ' firstname
            'osearcher.PropertiesToLoad.Add("sn") ' lastname
            'osearcher.PropertiesToLoad.Add("mail") ' mail
            'osearcher.PropertiesToLoad.Add("initials") ' initials
            'osearcher.PropertiesToLoad.Add("ou") ' organizational unit
            'osearcher.PropertiesToLoad.Add("userPrincipalName") ' login name
            'osearcher.PropertiesToLoad.Add("distinguishedName") ' distinguised name
            oresult = osearcher.FindAll()
    
            For Each result In oresult
                If Not result.GetDirectoryEntry.Properties("sn").Value Is Nothing Then
                    ' writes specific values retrieved from above - this is just a sample.
                    Response.Write(result.GetDirectoryEntry.Properties("cn").Value & ":" & result.GetDirectoryEntry.Properties("userPrincipalName").Value)
                End If
            Next


    Sunday, January 3, 2010 2:51 AM