Directory Services |
This topic provides information and code examples for reading properties that contain multiple values. As with properties that contain a single value, properties with multiple values are read using the Value property from the PropertyValueCollection object.
For properties that contain multiple values, use either a foreach statement to retrieve a Properties collection, or enumerate property values using an array.
The following code example uses the Properties collection to read multiple values.
[C#]
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
foreach(String s in ent.Properties["otherTelephone"] )
{
Console.WriteLine(s);
}
[Visual Basic .NET]
Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
Dim s As [String]
For Each s In ent.Properties("otherTelephone")
Console.WriteLine(s)
Next s
The following code example uses an array to read values.
[C#]
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
{
Console.WriteLine(ent.Properties["otherTelephone"][2]);
}
[Visual Basic .NET]
Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
If (True) Then
Console.WriteLine(ent.Properties("otherTelephone")(2))
End If