DirectoryEntries.Remove(DirectoryEntry) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Tar bort en medlem i den här samlingen.
public:
void Remove(System::DirectoryServices::DirectoryEntry ^ entry);
public void Remove(System.DirectoryServices.DirectoryEntry entry);
member this.Remove : System.DirectoryServices.DirectoryEntry -> unit
Public Sub Remove (entry As DirectoryEntry)
Parametrar
- entry
- DirectoryEntry
Namnet på det objekt som DirectoryEntry ska tas bort.
Undantag
Ett fel uppstod under anropet till det underliggande gränssnittet.
Exempel
I följande exempel skapas ett nytt DirectoryEntry objekt med den angivna sökvägen och sedan skapas en ny post i containern och sparas. Slutligen hämtar den den nya posten och tar bort den.
Imports System
Imports System.DirectoryServices
Class MyClass1
Shared Sub Main()
Try
Dim strPath As String = "IIS://localhost/W3SVC/1/Root"
Dim strName As String = ""
' Create a new 'DirectoryEntry' object 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 Domain Services'.
myDirectoryEntry.CommitChanges()
Console.WriteLine(myDirectoryEntry.Name + " entry is created in container.")
' Find 'Sample' entry in container.
myDirectoryEntry = myEntries.Find("Sample", myDE.SchemaClassName)
Console.WriteLine(myDirectoryEntry.Name + " found in container.")
' Remove 'Sample' entry from container.
strName = myDirectoryEntry.Name
myEntries.Remove(myDirectoryEntry)
Console.WriteLine(strName + " entry is removed from container.")
Catch e As Exception
Console.WriteLine("The following exception was raised : {0}", e.Message.ToString())
End Try
End Sub 'Main
End Class 'MyClass1
using System;
using System.DirectoryServices;
class MyClass1
{
static void Main()
{
try
{
String strPath = "IIS://localhost/W3SVC/1/Root";
String strName = "";
// Create a new 'DirectoryEntry' object 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 Domain Services'.
myDirectoryEntry.CommitChanges();
Console.WriteLine (myDirectoryEntry.Name +
" entry is created in container.");
// Find 'Sample' entry in container.
myDirectoryEntry = myEntries.Find("Sample", myDE.SchemaClassName);
Console.WriteLine(myDirectoryEntry.Name + " found in container.");
// Remove 'Sample' entry from container.
strName = myDirectoryEntry.Name;
myEntries.Remove(myDirectoryEntry);
Console.WriteLine(strName+ " entry is removed from container.");
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",
e.Message);
}
}
}
Kommentarer
Om posten som ska tas bort är en container måste containern vara tom. Om du vill ta bort en container och alla dess underordnade objekt använder du DeleteTree metoden .