我对我的C#项目进行了简短的探索.我想读出我们的活动目录并使用它:
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)
{ }
}
Run Code Online (Sandbox Code Playgroud)
现在我想读出其他属性,希望你能给我一个所有属性的列表.
谢谢
您只需通过以下代码即可完成
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)
{ }
}
Run Code Online (Sandbox Code Playgroud)