PropertyValueCollection::Remove Method (Object^)
Removes a specified property value from this collection.
Assembly: System.DirectoryServices (in System.DirectoryServices.dll)
Parameters
- value
-
Type:
System::Object^
The property value to remove.
| Exception | Condition |
|---|---|
| ArgumentNullException | The property value is a null reference (Nothing in Visual Basic). |
| COMException | An error occurred during the call to the underlying interface. |
When working with a multi-valued string property value, the Remove method will successfully remove the correct item. However, identifying the correct items by name is difficult with a multi-valued DNWithString property value (as the DNWithString COM class, which is used to store the DNWithString items, has 2 string properties representing the item). The way to remove such items is to find the object in the collection (by looping thru all the items), then call the Remove function with the object's pointer that you just found. This is illustrated in the example below.
// Bind to the AD object DirectoryEntry myUser = new DirectoryEntry("LDAP://AdServer:389/CN=MyUsername,CN=Users,DC=contoso,DC=com"); // Get the attribute PropertyValueCollection testAttribute = myUser.Properties["someAttribute"]; // Find the item in the collection that we want to delete DNWithString dnwsItemToRemove = null; foreach (DNWithString dnwsItem in testAttribute) { if (dnwsItem.StringValue.Equals("SomeValue")) { dnwsItemToRemove = dnwsItem; break; } } // Delete it testAttribute.Remove(dnwsItemToRemove); // Store the data myUser.CommitChanges();
Available since 1.1