本文整理汇总了C#中System.DirectoryServices.DirectorySearcher类的典型用法代码示例。如果您正苦于以下问题:C# DirectorySearcher类的具体用法?C# DirectorySearcher怎么用?C# DirectorySearcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectorySearcher类属于System.DirectoryServices命名空间,在下文中一共展示了DirectorySearcher类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: new DirectorySearcher()
//引入命名空间
using System;
using System.Net;
using System.DirectoryServices;
public class MainClass {
public static void Main() {
using (DirectoryEntry de = new DirectoryEntry("LDAP://yourV/OU=yourV, DC=explorer, DC=local"))
using (DirectorySearcher searcher = new DirectorySearcher()) {
de.Username = @"explorer\yourName";
de.Password = "password";
searcher.SearchRoot = de;
searcher.Filter = "(&(objectClass=user)(description=Auth*))";
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searcher.PropertiesToLoad.Add("name");
searcher.PropertiesToLoad.Add("description");
searcher.PropertiesToLoad.Add("givenName");
searcher.PropertiesToLoad.Add("wWWHomePage");
searcher.Sort = new SortOption("givenName", SortDirection.Ascending);
SearchResultCollection results = searcher.FindAll();
foreach (SearchResult result in results) {
ResultPropertyCollection props = result.Properties;
foreach (string propName in props.PropertyNames) {
Console.Write(propName + ": ");
Console.WriteLine(props[propName][0]);
}
}
}
}
}