次の方法で共有


子オブジェクトの列挙

1 つのコンテナ内のオブジェクトを列挙するには、各オブジェクトとそのプロパティの保持に使用できる 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.