小编fea*_*ood的帖子

Active Directory:PropertiesToLoad获取所有属性

我尝试从Active Directory中的对象获取所有属性的列表.

我现在拥有的是:

List<User> users = new List<User>();
try
{
    DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
    root = new DirectoryEntry("LDAP://" + root.Properties["defaultNamingContext"][0]);
    DirectorySearcher search = new DirectorySearcher(root);
    search.Filter = "(&(objectClass=user)(objectCategory=person))";

    search.PropertiesToLoad.Add("samaccountname");
    search.PropertiesToLoad.Add("displayname");
    search.PropertiesToLoad.Add("mail");
    search.PropertiesToLoad.Add("telephoneNumber");
    search.PropertiesToLoad.Add("department");
    search.PropertiesToLoad.Add("title");

    SearchResultCollection results = search.FindAll();
    if (results != null)
    {
        foreach (SearchResult result in results)
        {
            foreach (DictionaryEntry property in result.Properties)
            {
                Debug.Write(property.Key + ": ");
                foreach (var val in (property.Value as ResultPropertyValueCollection)) { 
                    Debug.Write(val +"; ");
                }
                Debug.WriteLine("");
            }
        }
    }
}
catch (Exception ex) …
Run Code Online (Sandbox Code Playgroud)

c# active-directory

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

active-directory ×1

c# ×1