Creates a request to create a new entry in the container.
[Visual Basic] Public Function Add( _ ByVal name As String, _ ByVal schemaClassName As String _ ) As DirectoryEntry [C#] public DirectoryEntry Add( string name, string schemaClassName ); [C++] public: DirectoryEntry* Add( String* name, String* schemaClassName ); [JScript] public function Add( name : String, schemaClassName : String ) : DirectoryEntry;
A DirectoryEntry that represents the new entry.
| Exception Type | Condition |
|---|---|
| COMException | An error occurred during the call to the underlying interface. |
Note You must call the CommitChanges method on the new entry to make the creation permanent. This allows you to set mandatory property values on the new entry. The providers each have different requirements for properties that need to be set before a call to the CommitChanges method is made. If those requirements are not met, the provider might throw an exception. Check with your provider to determine which properties must be set before committing changes.
[Visual Basic, C#, C++] The following example creates a new DirectoryEntry with a specified path, then creates a new entry in the container and saves it.
[Visual Basic] Dim strPath As String = "IIS://localhost/W3SVC/1/Root" ' Create a new 'DirectoryEntry' with the given path. Dim myDE As New DirectoryEntry(strPath) Dim myEntries As DirectoryEntries = myDE.Children ' Create a new entry 'Sample' in the container. Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("Sample", myDE.SchemaClassName) ' Save changes of entry in the 'Active Directory'. myDirectoryEntry.CommitChanges() Console.WriteLine(myDirectoryEntry.Name + " entry is created in container.") [C#] String strPath = "IIS://localhost/W3SVC/1/Root"; // Create a new 'DirectoryEntry' with the given path. DirectoryEntry myDE = new DirectoryEntry(strPath); DirectoryEntries myEntries = myDE.Children; // Create a new entry 'Sample' in the container. DirectoryEntry myDirectoryEntry = myEntries.Add("Sample", myDE.SchemaClassName); // Save changes of entry in the 'Active Directory'. myDirectoryEntry.CommitChanges(); Console.WriteLine (myDirectoryEntry.Name + " entry is created in container."); [C++] String* strPath = S"IIS://localhost/W3SVC/1/Root"; // Create a new 'DirectoryEntry' with the given path. DirectoryEntry* myDE = new DirectoryEntry(strPath); DirectoryEntries* myEntries = myDE->Children; // Create a new entry 'Sample' in the container. DirectoryEntry* myDirectoryEntry = myEntries->Add(S"Sample", myDE->SchemaClassName); // Save changes of entry in the 'Active Directory'. myDirectoryEntry->CommitChanges(); Console::WriteLine("{0} entry is created in container.", myDirectoryEntry->Name);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
DirectoryEntries Class | DirectoryEntries Members | System.DirectoryServices Namespace | DirectoryEntry