Поделиться через


Setting Properties with Multiple Values

This topic shows how to set multi-value properties using the following methods:

  • Add is a method of PropertyValueCollection that appends an additional property value to a multi-value property.
  • AddRange is a method of PropertyValueCollection that appends multiple values to a multi-value property.
  • Insert is a method of PropertyValueCollection that inserts a property value by its index position into a multi-value property. This position is only set on the client; when you commit it to the directory, there is no guarantee that it will be saved to this index position in Active Directory Domain Services.

You can also set values using an indexed array.

When you set a property value, the data is saved in the property cache. To write the new data to the directory, call the CommitChanges method. For more information, see The Property Cache.

The following code example shows how to use the AddRange method.

Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
ent.Properties("otherTelephone").AddRange(New Object() {"(425) 523 1462", "(523) 125 6321"})
ent.CommitChanges()
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
ent.Properties["otherTelephone"].AddRange(new object[] {"(425) 523 1462","(523) 125 6321"});
ent.CommitChanges();

The following code example shows how to use the Insert method.

Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
ent.Properties("otherTelephone").Insert(2, "525 623 5423")
ent.CommitChanges()
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
ent.Properties["otherTelephone"].Insert(2, "525 623 5423");
ent.CommitChanges();

The following code example shows how to use an array to set a value on a multi-value property.

Dim ent As New DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com")
ent.Properties("otherTelephone")(0) = "425 263 6234"
ent.CommitChanges()
DirectoryEntry ent = new DirectoryEntry("LDAP://Fabrikam/CN=My Username,CN=Users,DC=Fabrikam,DC=com");
ent.Properties["otherTelephone"][0] = "425 263 6234";
ent.CommitChanges();

See Also

Reference

System.DirectoryServices
PropertyValueCollection
DirectoryEntry

Concepts

Properties with Multiple Values

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.