【发布时间】:2009-03-12 22:46:25
【问题描述】:
谁能提供一个如何循环 System.DirectoryServices.PropertyCollection 并输出属性名称和值的示例?
我正在使用 C#。
@JaredPar - PropertyCollection 没有名称/值属性。它确实有一个 PropertyNames 和 Values,类型为 System.Collection.ICollection。我不知道构成 PropertyCollection 对象的基线对象类型。
再次@JaredPar - 我最初用错误的类型错误地标记了问题。那是我的错。
更新:根据 Zhaph - Ben Duguid 的输入,我能够开发以下代码。
using System.Collections;
using System.DirectoryServices;
public void DisplayValue(DirectoryEntry de)
{
if(de.Children != null)
{
foreach(DirectoryEntry child in de.Children)
{
PropertyCollection pc = child.Properties;
IDictionaryEnumerator ide = pc.GetEnumerator();
ide.Reset();
while(ide.MoveNext())
{
PropertyValueCollection pvc = ide.Entry.Value as PropertyValueCollection;
Console.WriteLine(string.Format("Name: {0}", ide.Entry.Key.ToString()));
Console.WriteLine(string.Format("Value: {0}", pvc.Value));
}
}
}
}
【问题讨论】:
标签: c# asp.net iis directoryservices