Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 目录项属性_C#_Active Directory - Fatal编程技术网

C# 目录项属性

C# 目录项属性,c#,active-directory,C#,Active Directory,我对我的C#项目有一个简短的要求。我想读出我们的active directory并使用以下内容: System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry); foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll()) {

我对我的C#项目有一个简短的要求。我想读出我们的active directory并使用以下内容:

System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
        System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
        try
        {
            myRow["eMail"] = de.Properties["Mail"].Value.ToString();
        }
        catch (Exception)
        { }
}
现在我想读出其他属性,希望你能给我一个所有属性的列表


谢谢

您只需使用下面的代码即可完成

 DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

            foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
            {
                try
                {
                    foreach (string property in resEnt.Properties.PropertyNames)
                    {
                        string value = resEnt.Properties[property][0].ToString();

                        Console.WriteLine(property + ":" + value);
                    }
                }
                catch (Exception)
                { }
            }

你能再解释一下吗?谢谢:)这正是我需要的