Search code examples
c#asp.netiisdirectoryservices

How do I loop through a PropertyCollection


Can anyone provide an example of how to loop through a System.DirectoryServices.PropertyCollection and output the property name and value?

I am using C#.

The PropertyCollection does not have a Name/Value property. It does have a PropertyNames and Values, type System.Collection.ICollection. I do not know the baseline object type that makes up the PropertyCollection object.


Solution

  • The PropertyCollection has a PropertyName collection - which is a collection of strings (see PropertyCollection.Contains and PropertyCollection.Item both of which take a string).

    You can usually call GetEnumerator to allow you to enumerate over the collection, using the usual enumeration methods - in this case you'd get an IDictionary containing the string key, and then an object for each item/values.