G
Guest
Hi,
I've written sone C# classes to search the active directory for users - see
code below.
The code works fine but is very slow when I'm iterating through the
directory and getting the attributes via the Properties collection.
Extracting over 500 objects is OK but it takes an extra 15 seconds when
accesing the data via the Properties["prop name"].value method.
Does anyone know a quicker method - if there is none I'm going to use
remoting to pre load the information but would be interested to know.
Regards
Mike
public void GetUsers(string domainController)
{
DirectorySearcher directorySearcher = new DirectorySearcher(
new DirectoryEntry("LDAP://" + domainController),
"(&(objectCategory=Person)(objectClass=user))");
SearchResultCollection entries = directorySearcher.FindAll();
foreach (SearchResult result in entries)
{
DirectoryEntry entry= result.GetDirectoryEntry();
try
{
userData.UserID = entry.Properties["employeeID"].Value.ToString();
userData.FirstName =
entry.Properties["givenName"].Value.ToString();
userData.MiddleName =
entry.Properties"middleName"].Value.ToString();
userData.LastName = entry.Properties["sn"].Value.ToString();
userData.FullName =
entry.Properties["displayName"].Value.ToString();
userData.EmailAddress = entry.Properties["mail"].Value.ToString();
userData.Department =
entry.Properties["department"].Value.ToString();
userData.Location =
entry.Properties["physicalDeliveryOfficeName"].Value.ToString();
userData.JobTitle = entry.Properties["title"].Value.ToString();
userData.Description =
entry.Properties["description"].Value.ToString();
userCollection.Add(this.userData);
}
I've written sone C# classes to search the active directory for users - see
code below.
The code works fine but is very slow when I'm iterating through the
directory and getting the attributes via the Properties collection.
Extracting over 500 objects is OK but it takes an extra 15 seconds when
accesing the data via the Properties["prop name"].value method.
Does anyone know a quicker method - if there is none I'm going to use
remoting to pre load the information but would be interested to know.
Regards
Mike
public void GetUsers(string domainController)
{
DirectorySearcher directorySearcher = new DirectorySearcher(
new DirectoryEntry("LDAP://" + domainController),
"(&(objectCategory=Person)(objectClass=user))");
SearchResultCollection entries = directorySearcher.FindAll();
foreach (SearchResult result in entries)
{
DirectoryEntry entry= result.GetDirectoryEntry();
try
{
userData.UserID = entry.Properties["employeeID"].Value.ToString();
userData.FirstName =
entry.Properties["givenName"].Value.ToString();
userData.MiddleName =
entry.Properties"middleName"].Value.ToString();
userData.LastName = entry.Properties["sn"].Value.ToString();
userData.FullName =
entry.Properties["displayName"].Value.ToString();
userData.EmailAddress = entry.Properties["mail"].Value.ToString();
userData.Department =
entry.Properties["department"].Value.ToString();
userData.Location =
entry.Properties["physicalDeliveryOfficeName"].Value.ToString();
userData.JobTitle = entry.Properties["title"].Value.ToString();
userData.Description =
entry.Properties["description"].Value.ToString();
userCollection.Add(this.userData);
}