locked
Getting Properties Dynamically? RRS feed

  • Question

  • User-419591595 posted

    Using code from my previous LDAP post ( http://forums.asp.net/thread/1306867.aspx ), how can I iterate the properties without knowing them. For example - here is the code (which everything works beautifully after help) - but I only know of the properties that I've listed (employeenumber, givenname and cn) - There are some other properties (such as position number, etc.) that I want to get, but the LDAP guys aren't forth-coming with the names - can I iterate them all or do I have to guess them?

    Code:

     

    private System.Collections.Hashtable GetAllUnCachedLDAPUsers()
    {
    //To retrieve list of all LDAP users
    //This function returns HashTable

    DirectoryEntry entry = new DirectoryEntry(sLDAPConnectionString);
    DirectorySearcher oSearcher = new DirectorySearcher(entry);
    entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
    SearchResultCollection oResults;
    System.Collections.Hashtable RetArray = new System.Collections.Hashtable();
    try
    {
       oSearcher.PropertiesToLoad.Add("employeenumber");
       oSearcher.PropertiesToLoad.Add("givenname");
       oSearcher.PropertiesToLoad.Add("cn");
       oResults = oSearcher.FindAll();

       foreach (SearchResult oResult in oResults)
       {
          if ((string)oResult.Properties["cn"][0] != "" && (string)oResult.Properties["employeenumber"][0] != null)
             {
                RetArray.Add(oResult.Properties["employeenumber"][0], oResult.Properties["cn"][0]);
             }
       }
    }
    catch (Exception e)
    {
       return RetArray;
    }
    return RetArray;
    }

    Thursday, June 8, 2006 11:45 AM

All replies