Share via


DirectoryEntry

The DirectoryEntry class encapsulates a node or object in the Active Directory hierarchy.

The DirectoryEntry class is derived from the System.ComponentModel.Component class.

Public Constructors

The DirectoryEntry class has the following public constructors.

Constructor Description
DirectoryEntry()

Initializes a new instance of the DirectoryEntry class.

DirectoryEntry(Object)

Initializes a new instance of the DirectoryEntry class that binds to the specified native Active Directory object.

DirectoryEntry(String)

Initializes a new instance of the DirectoryEntry class that binds this instance to the node in Active Directory located at the specified path.

DirectoryEntry(String, String, String)

Initializes a new instance of the DirectoryEntry class. The Path, Username, and Password properties are set to the specified values.

DirectoryEntry(String, String, String, AuthenticationTypes)

Initializes a new instance of the DirectoryEntry class. The Path, Username, Password, and AuthenticationType properties are set to the specified values.

Public Methods

The DirectoryEntry class has the following public methods.

Method Description
Close()

Closes the DirectoryEntry and releases any system resources associated with this component.

CommitChanges()

Saves any changes to the entry in the Active Directory store.

CopyTo(DirectoryEntry)

Overloaded. Creates a copy of this entry as a child of the specified parent.

CopyTo(DirectoryEntry, String)

Overloaded. Creates a copy of this entry as a child of the specified parent, with the specified new name.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

DeleteTree()

Deletes this entry and its entire subtree from the Active Directory hierarchy.

Dispose()

Overloaded. Releases the resources used by the Component.

Equals(Object)

Overloaded. Determines whether two Object instances are equal.

Exists(String)

Static (Shared). Searches the directory store at the specified path to see whether an entry exists.

GetHashCode()

Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

GetType()

Gets the Type of the current instance.

InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

Invoke(String, Object[])

Calls a method on the native Active Directory.

InvokeGet(String)

Supports the .NET Framework and cannot be used in your application.

InvokeSet(String, Object[])

Supports the .NET Framework and cannot be used in your application.

MoveTo(DirectoryEntry)

Overloaded. Moves this entry to the specified parent.

MoveTo(DirectoryEntry, String)

Overloaded. Moves this entry to the specified parent.

RefreshCache()

Overloaded. Loads the property values for this directory entry into the property cache.

RefreshCache(String[])

Overloaded. Loads the property values for this directory entry into the property cache.

Rename(String)

Changes the name of this entry.

ToString()

Returns a String that represents the current Object.

Public Properties

The DirectoryEntry class has the following public properties.

Property Description
AuthenticationType Data type: AuthenticationTypes
Access type: Read/write

Gets or sets the type of authentication to use.

Children Data type: DirectoryEntries
Access type: Read-only

Gets a DirectoryEntries containing the child entries of this node in the Active Directory hierarchy.

Container Data type: IContainer
Access type: Read-only

Gets the IContainer that contains the Component.

Guid Data type: Guid
Access type: Read-only

Gets the globally unique identifier (GUID) of the DirectoryEntry.

Name Data type: String
Access type: Read-only

Gets the name of the object as named with the underlying directory service.

NativeGuid Data type: String
Access type: Read-only

Gets the globally unique identifier of the DirectoryEntry, as returned from the provider.

NativeObject Data type: Object
Access type: Read-only

Gets the native Active Directory Service Interfaces (ADSI) object.

Parent Data type: DirectoryEntry
Access type: Read-only

Gets this entry's parent in the Active Directory hierarchy.

Password Data type: String
Access type: Write-only

Gets or sets the password to use when authenticating the client.

Path Data type: String
Access type: Read/write

Gets or sets the path for this DirectoryEntry.

Properties Data type: PropertyCollection
Access type: Read-only

Gets a PropertyCollection of properties set on this object.

SchemaClassName Data type: String
Access type: Read-only

Gets the name of the schema used for this DirectoryEntry.

SchemaEntry Data type: DirectoryEntry
Access type: Read-only

Gets the DirectoryEntry that holds schema information for this entry. An entry's schema determines a list of its mandatory and optional property names.

Site Data type: ISite
Access type: Read/write

Gets or sets the ISite of the Component.

UsePropertyCache Data type: Boolean
Access type: Read/write

Gets or sets a value indicating whether the cache should be committed after each operation.

Username Data type: String
Access type: Read/write

Gets or sets the user name to use when authenticating the client.

Public Events

The DirectoryEntry class has the following public event.

Event Description
Disposed

Overloaded. Overridden. Disposes of the resources (other than memory) used by the DirectoryEntry.

Protected Methods

The DirectoryEntry class has the following protected methods.

Method Description
Dispose(Boolean)

Overloaded. Overridden. Disposes of the resources (other than memory) used by the DirectoryEntry.

Finalize()

Overridden. Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. In C# and C++, finalizers are expressed using destructor syntax.

GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

MemberwiseClone()

Creates a shallow copy of the current Object.

Protected Properties

The DirectoryEntry class has the following protected properties.

Property Description
DesignMode Data type: Boolean
Access type: Read-only

Gets a value that indicates whether the Component is currently in design mode.

Events Data type: EventHandlerList
Access type: Read-only

Gets the list of event handlers that are attached to this Component.

Remarks

Use this class for binding to objects, or reading and updating attributes. DirectoryEntry, along with helper classes, provides support for life-cycle management and navigation methods. These include creating, deleting, renaming, moving a child node, and enumerating children. After you modify a node, you must commit your changes in order for them to be saved to the tree. For more information, see the CommitChanges property.

DirectoryEntry can be used to access regular entries and some, but not all, information from schema entries.

The Active Directory hierarchy contains up to several thousand nodes. Each node represents an object, such as a network printer or a user in a domain. Corporate networks constantly change as new employees are hired and objects such as network printers and computers are added. Active Directory Service Interfaces (ADSI) technology provides ways to programmatically add these objects to the directory tree.

To create a directory entry in the hierarchy, use the Children property. The Children property is a collection that provides an Add method, through which you add a node to the collection directly below the parent node that you are currently bound to. When adding a node to the collection, you must specify a name for the new node and the name of a schema template that you want to associate with the node. For example, you might want to use a schema titled "Computer" to add new computers to the hierarchy.

This class also contains attribute caching, which can be useful for optimizing network traffic. To use attribute caching, see the UsePropertyCache property.

The classes associated with the DirectoryEntry component can be used with any of the Active Directory service providers. Some of the current providers are Internet Information Services (IIS), Lightweight Directory Access Protocol (LDAP), Novell NetWare Directory Service (NDS), and WinNT.

Note  It is assumed that you have a general understanding of Active Directory before using this class. For more information, see the System.DirectoryServices namespace overview.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Requirements

Client Requires Windows XP Home Edition, Windows XP Professional, Windows Me, or Windows 98.
Server Requires Windows Server 2003, Windows 2000, or Windows NT 4.0.
Namespace

Defined in System.DirectoryServices.

Assembly

Requires System.DirectoryServices (in System.DirectoryServices.dll).

.NET Framework

Requires .NET Framework 1.0.

See Also

DirectoryEntry, DirectoryEntry Constructors, DirectoryEntry Methods, Framework Services Namespaces in Visual Studio, Managed Extensions for C++ Programming, PropertyCollection, PropertyValueCollection, ReferralChasingOption, SearchResult, SearchResultCollection, ResultPropertyCollection, ResultPropertyValueCollection, SearchScope, SortDirection, SortOption, System.DirectoryServices Namespace