locked
Need to find all users in directory. RRS feed

  • Question

  • User964866022 posted

    I m writing a web page to display user name and his contact number.


    I m giving user a choice to enter user name once he enter the name i should be able to search in active directory and return all user starting with (inputed name).


    DirectorySearcher deSearch = new DirectorySearcher(de);

                //set the search filter    
                deSearch.SearchRoot = de;
                String UserName = "milindk";
                deSearch.Filter = "(&(objectCategory=user)(samaccountname=" + UserName + "))";


    Above code needs exact login name like adamjo which is not the purpose.


    i should be able to display all possible possibilities for example if user enters adam i should give him choice to select whether he want to see adam josef or adam john e.t.c.


    How would i achieve this.

    Is there any property to find first name from active directory?


    Monday, February 15, 2010 5:13 AM

Answers

  • User197322208 posted

    put an try { }

    catch(<type of exception> var)
    {

    Response.Write("it has no phone!")
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 15, 2010 8:37 AM

All replies

  • User197322208 posted

    samaccountname=*" + UserName + "*"


    or for first name

    givenname=*" + UserName + "*"


    or for last name

    sn=*" + UserName + "*"


    Monday, February 15, 2010 6:58 AM
  • User964866022 posted

    thanks for your reply it was indeed helpfull but now i m getting some error while executing the code.


    Error :

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    Error Line:Dim valCol2 As DirectoryServices.ResultPropertyValueCollection = sr.Properties("telephonenumber")


    This error comes when there is no telephone entry present how would i avoid this.

    My code is as follows :

    Dim c1 As Integer = results.Count
                Dim i As Integer = 0

    Response.Write("<table border=2>")
                
                While c1 > 0
                    Response.Write("<tr>")
                    Response.Write("<td>")
                    Dim sr As DirectoryServices.SearchResult = results(i)
                    Dim valColl As DirectoryServices.ResultPropertyValueCollection = sr.Properties("samaccountname")
                    Dim valCol2 As DirectoryServices.ResultPropertyValueCollection = sr.Properties("telephonenumber")
                    Response.Write(valColl(0).ToString())
                    Response.Write("</td>")
                    Response.Write("<td>")
                    Response.Write("")
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write(valCol2(0).ToString())
                    Response.Write("</td>")
                    Response.Write("</tr>")
                 
                    c1 = c1 - 1
                    i += 1
                End While
                Response.Write("</table>")

    Monday, February 15, 2010 7:57 AM
  • User197322208 posted

    put an try { }

    catch(<type of exception> var)
    {

    Response.Write("it has no phone!")
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 15, 2010 8:37 AM