DirectoryEntries.Remove(DirectoryEntry) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 컬렉션의 멤버를 삭제합니다.
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)
매개 변수
- entry
- DirectoryEntry
삭제할 개체의 DirectoryEntry 이름입니다.
예외
기본 인터페이스를 호출하는 동안 오류가 발생했습니다.
예제
다음 예제에서는 지정된 경로를 사용하여 새 DirectoryEntry 개체를 만든 다음 컨테이너에 새 항목을 만들고 저장합니다. 마지막으로 새 항목을 검색하고 삭제합니다.
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);
}
}
}
설명
제거할 항목이 컨테이너인 경우 컨테이너는 비어 있어야 합니다. 컨테이너 및 모든 자식을 삭제하려면 이 메서드를 DeleteTree 사용합니다.