//person
strFilter = String.Format("(&(objectCategory=person)(objectClass=user)({0}={1}))", strFieldNm, strValue);
//distribution group
strFilter = String.Format("(&(objectCategory=group)(objectClass=group)({0}={1}))", strFieldNm, strValue);
private SearchUsersList GetUsersOrDistributionGroups(string strFilter, string strLDAPPath, bool blnIsGroup)
{
SearchUsersList objResult = new SearchUsersList();
DirectorySearcher search = null;
try
{
if (strFilter != String.Empty)
{
search = new DirectorySearcher(new DirectoryEntry(strLDAPPath), strFilter);
}
else
{
search = new DirectorySearcher(strFilter);
}
if (search != null)
{
foreach (SearchResult result in search.FindAll())
{
DirectoryEntry entry = result.GetDirectoryEntry();
if (entry.Properties["mail"].Value != null && !String.IsNullOrEmpty(entry.Properties["mail"].Value.ToString()))
{
SearchUsers objUser = new SearchUsers();
objUser.ID = entry.Properties["samaccountname"].Value.ToString();
objUser.MailAddress = entry.Properties["mail"].Value.ToString();
objUser.UserName = entry.Properties["name"].Value.ToString();
objUser.UserType = blnIsGroup ? "LDAP Distribution Group" : "LDAP User";
objResult.Add(objUser);
}
}
}
}
catch
{
throw;
}
return objResult;
}
A blog by an ordinary Linux user who uses Windows in his day job.
Tuesday, April 20, 2010
Retrieving data from LDAP...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment