자식 개체 열거
컨테이너에서 개체를 열거하려면 각 개체 및 해당 속성을 보유하는 데 사용할 수 있는 DirectoryEntry 개체를 만듭니다. 그런 다음 DirectoryEntry에서 제공하는 속성을 사용하여 이름 특성과 같은 데이터를 가져올 수 있습니다. Using foreach with Arrays 문을 사용하여 컨테이너의 각 개체를 반복할 수 있습니다.
다음 코드 샘플에서는 사용자 컨테이너를 열거하는 방법을 보여 줍니다.
Try
' Bind to the container to enumerate.
Dim ent As New DirectoryEntry("LDAP://CN=users,OU=Marketing,DC=fabrikam,DC=com")
' Create an object to use for individual objects in the container and iterate
' through the container.
Dim child As DirectoryEntry
For Each child In ent.Children
' Write the name and path for each object in the container.
Console.WriteLine("{0} {1}", child.Name, child.Path)
Next child
Catch Exception1 As Exception
' Handle errors.
End Try
try
{
// Bind to the container to enumerate.
DirectoryEntry ent = new DirectoryEntry("LDAP://CN=users,OU=Marketing,DC=fabrikam,DC=com");
// Create an object to use for individual objects in the container and iterate
// through the container.
foreach( DirectoryEntry child in ent.Children)
{
// Write the name and path for each object in the container.
Console.WriteLine( "{0} {1}", child.Name, child.Path);
}
}
catch
{
// Handle errors.
}
참고 항목
참조
System.DirectoryServices
DirectoryEntry
개념
Send comments about this topic to Microsoft.
Copyright © 2007 by Microsoft Corporation. All rights reserved.