Renaming an Object

DirectoryEntry provides the Rename method to rename objects in the directory.

The following example shows how to use Rename to change the name of a User object.

Try
    ' Bind to the user object to modify.
    Dim child As New DirectoryEntry("LDAP://CN=My User Name,OU=Marketing,DC=fabrikam,DC=com")
    ' Rename the object to Jeff Smith.
    child.Rename("CN=New User Name")
Catch COMEx As COMException
    ' If a COMException is thrown, then the following code can capture the text of the error.
    ' For instructions about handling COM exceptions, see Handling Errors.
    Console.WriteLine(COMEx.ErrorCode)
End Try '}
try
{
    // Bind to the user object to modify.
    DirectoryEntry child = new DirectoryEntry("LDAP://CN=My User Name,OU=Marketing,DC=fabrikam,DC=com");
    // Rename the object to Jeff Smith.
    child.Rename("CN=New User Name");
}
catch (COMException COMEx)
{
    // If a COMException is thrown, then the following code can capture the text of the error.
    // For more information about handling COM exceptions, see Handling Errors.
    Console.WriteLine(COMEx.ErrorCode);
)

See Also

Reference

System.DirectoryServices
DirectoryEntry

Concepts

Creating, Deleting, Renaming and Moving Objects

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.