Share via


移动目录对象

要将对象移动到新容器,请使用 MoveTo 方法。

下面的示例说明如何使用 MoveTo 移动用户对象。

Try
    ' Bind to the object to be moved.
    Dim NewUser As New DirectoryEntry("LDAP://CN=User Name,OU=Sales,DC=fabrikam,DC=com")
    ' Use the MoveTo property to define the new container you want to move the object to.
    NewUser.MoveTo(New DirectoryEntry("LDAP://OU=HR,DC=fabrikam,DC=com"))
Catch InvOpEx As InvalidOperationException
    ' Handle InvalidOperationException.
    Console.WriteLine(InvOpEx.Message);

Catch COMEx As COMException
    ' Handle COMException.
    ' For more information about handling COM exceptions, see Handling Errors.
    Console.WriteLine(COMEx.Message);

End Try
try
{
    // Bind to the object to be moved.
    DirectoryEntry NewUser = new DirectoryEntry("LDAP://CN=User Name,OU=Sales,DC=fabrikam,DC=com");
    // Use the MoveTo property to define the new container you want to move the object to.
    NewUser.MoveTo( new DirectoryEntry("LDAP://OU=HR,DC=fabrikam,DC=com"));
}
catch (InvalidOperationException InvOpEx)
{
    // Handle InvalidOperationException.
    Console.WriteLine(InvOpEx.Message);
}
catch (COMException COMEx)
{
    // Handle COMException.
    // For more information about handling COM exceptions, see Handling Errors.
    Console.WriteLine(COMEx.Message);
}

另请参见

参考

System.DirectoryServices
DirectoryEntry

概念

创建、删除、重命名和移动对象

Send comments about this topic to Microsoft.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。