Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem in getting the List of user 's from ADS.

Problem in getting the List of user 's from ADS.

Scheduled Pinned Locked Moved C#
windows-adminhelpcsharp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vinay_K
    wrote on last edited by
    #1

    Hi.. I need to get the List of all the user Name from Active Directory, i used the following code.

    try{
    ADEntry = new DirectoryEntry("LDAP://" + Session["DominName"].ToString() + ".net", txtUserName.Text.ToString(),
    txtPassword.Text.ToString(), AuthenticationTypes.Secure);

                nativeObject = ADEntry.NativeObject;
            }
            catch (Exception)
            {
    
    
    
            DirectorySearcher mySearcher = null;
    
           
    
            mySearcher = new DirectorySearcher(ADEntry);
            mySearcher.SearchRoot = ADEntry;
            mySearcher.Filter = "(&(objectClass=USER))";            
            mySearcher.SearchScope = SearchScope.Subtree;
            mySearcher.PropertiesToLoad.Add("SAMACCOUNTNAME");
            mySearcher.PropertiesToLoad.Add("cn");       
            mySearcher.PropertiesToLoad.Add("mail");           
    
            SearchResult srh = null;
            srh = mySearcher.FindOne();
            int intSerialNo = 1;
    
            //SearchResultCollection result = mySearcher.FindAll();
    
    
    
            foreach (SearchResult resEnt in mySearcher.FindAll())
            {    
    
                resEnt.Properties\["SAMACCOUNTNAME"\]\[0\].ToString();
                    
                resEnt.Properties\["cn"\]\[0\].ToString();
                    
                resEnt.Properties\["mail"\]\[0\].ToString();
                    
            }
    

    But it is listing Max 1000 users details but there are 2000 entries in the ADS under "user" group.. Please anyone Help me to get the list of all the 2000 user's list in ADS.. if there is a limitation for LDAP protocol.. Can any one suggest other protocol, i tried with WINNT, NDS and IIS also..

    M 1 Reply Last reply
    0
    • V vinay_K

      Hi.. I need to get the List of all the user Name from Active Directory, i used the following code.

      try{
      ADEntry = new DirectoryEntry("LDAP://" + Session["DominName"].ToString() + ".net", txtUserName.Text.ToString(),
      txtPassword.Text.ToString(), AuthenticationTypes.Secure);

                  nativeObject = ADEntry.NativeObject;
              }
              catch (Exception)
              {
      
      
      
              DirectorySearcher mySearcher = null;
      
             
      
              mySearcher = new DirectorySearcher(ADEntry);
              mySearcher.SearchRoot = ADEntry;
              mySearcher.Filter = "(&(objectClass=USER))";            
              mySearcher.SearchScope = SearchScope.Subtree;
              mySearcher.PropertiesToLoad.Add("SAMACCOUNTNAME");
              mySearcher.PropertiesToLoad.Add("cn");       
              mySearcher.PropertiesToLoad.Add("mail");           
      
              SearchResult srh = null;
              srh = mySearcher.FindOne();
              int intSerialNo = 1;
      
              //SearchResultCollection result = mySearcher.FindAll();
      
      
      
              foreach (SearchResult resEnt in mySearcher.FindAll())
              {    
      
                  resEnt.Properties\["SAMACCOUNTNAME"\]\[0\].ToString();
                      
                  resEnt.Properties\["cn"\]\[0\].ToString();
                      
                  resEnt.Properties\["mail"\]\[0\].ToString();
                      
              }
      

      But it is listing Max 1000 users details but there are 2000 entries in the ADS under "user" group.. Please anyone Help me to get the list of all the 2000 user's list in ADS.. if there is a limitation for LDAP protocol.. Can any one suggest other protocol, i tried with WINNT, NDS and IIS also..

      M Offline
      M Offline
      Mirko1980
      wrote on last edited by
      #2

      Yes, LDAP has a limit of 1000 result for a single search. To avoid that you must perform a paged search. To do that, just set the PageSize property of the DirectorySearcher object to a value greater than 0 (e.g. 500 or 750) before calling the FindAll method. The MSDN documentation for that is Here[^].

      V 1 Reply Last reply
      0
      • M Mirko1980

        Yes, LDAP has a limit of 1000 result for a single search. To avoid that you must perform a paged search. To do that, just set the PageSize property of the DirectorySearcher object to a value greater than 0 (e.g. 500 or 750) before calling the FindAll method. The MSDN documentation for that is Here[^].

        V Offline
        V Offline
        vinay_K
        wrote on last edited by
        #3

        Thank you very much Mirko. :) :) :) :) :) regards :) skvs :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups