if (!String.IsNullOrEmpty(domainName)) { DirectoryEntry myDirectoryEntry = new DirectoryEntry(String.Format("LDAP://{0}", domainName)); DirectorySearcher mySearcher = new DirectorySearcher(myDirectoryEntry); SortOption mySort = new SortOption("sn", SortDirection.Ascending); mySearcher.Filter = ("(objectCategory=person)"); mySearcher.Sort = mySort; foreach (SearchResult resEnt in mySearcher.FindAll()) { if ( System.Text.RegularExpressions.Regex.IsMatch(resEnt.Properties["displayName"][0].ToString(), " |admin|test|service|system|[$]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { int space = resEnt.Properties["displayName"][0].ToString().IndexOf(" "); string formattedName = String.Format("{0}", resEnt.Properties["displayName"][0].ToString().Substring(space).PadRight(25), ); userList.Add(formattedName); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)