Share via


DirectoryEntries.Find メソッド

定義

このコレクションのメンバーを返します。

オーバーロード

Find(String)

指定した名前を持つこのコレクションのメンバーを返します。

Find(String, String)

指定した名前を持ち、指定した型のこのコレクションのメンバーを返します。

Find(String)

ソース:
DirectoryEntries.cs
ソース:
DirectoryEntries.cs
ソース:
DirectoryEntries.cs

指定した名前を持つこのコレクションのメンバーを返します。

public:
 System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name);
public System.DirectoryServices.DirectoryEntry Find (string name);
member this.Find : string -> System.DirectoryServices.DirectoryEntry
Public Function Find (name As String) As DirectoryEntry

パラメーター

name
String

検索する子オブジェクトの名前を格納します。

戻り値

見つかった子オブジェクトを表す DirectoryEntry

例外

Active Directory ドメイン サービスがコンテナーではありません。

基になるインターフェイスへの呼び出し中にエラーが発生しました。

注釈

異なる型の子オブジェクトの名前が同じ場合は、最初に一致する子オブジェクトが返されます。

注意

インターネット インフォメーション サービス (IIS) プロバイダーでは、このメソッドはサポートされていません。 オーバーロードされた Find メソッドを使用し、 パラメーターに空の文字列 ("") を schemaClassName 指定します。

一致する結果が見つからない場合は、 DirectoryServicesCOMException エラー コード0x2030を含む がスローされます。

適用対象

Find(String, String)

ソース:
DirectoryEntries.cs
ソース:
DirectoryEntries.cs
ソース:
DirectoryEntries.cs

指定した名前を持ち、指定した型のこのコレクションのメンバーを返します。

public:
 System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name, System::String ^ schemaClassName);
public System.DirectoryServices.DirectoryEntry Find (string name, string schemaClassName);
public System.DirectoryServices.DirectoryEntry Find (string name, string? schemaClassName);
member this.Find : string * string -> System.DirectoryServices.DirectoryEntry
Public Function Find (name As String, schemaClassName As String) As DirectoryEntry

パラメーター

name
String

検索する子ディレクトリ オブジェクトの名前。

schemaClassName
String

検索する子ディレクトリ オブジェクトのクラス名。

戻り値

見つかった子オブジェクトを表す DirectoryEntry オブジェクト。

例外

Active Directory ドメイン サービスがコンテナーではありません。

基になるインターフェイスへの呼び出し中にエラーが発生しました。

次の Visual Basic .NET の例では、指定したパスを持つ新しい DirectoryEntry オブジェクトを作成し、コンテナーに新しいエントリを作成して保存します。 新しく作成されたエントリの取得を試みます。

Try  
     Dim myEntry1 As DirectoryEntry  
     Dim myEntry2 As DirectoryEntry  
     Dim strPath As String = "LDAP://DC=fabrikam,DC=com"  

     ' Create a 'DirectoryEntry' object with the given path.  
     Dim myDE As New DirectoryEntry(strPath)  
     Dim myEntries As DirectoryEntries = myDE.Children  

     ' Create a new entry in the container.  
     myEntry1 = myEntries.Add("CN=Sample Entry", myDE.SchemaClassName)  
     ' Save changes in the 'Active Directory Domain Services' store.  
     myEntry1.CommitChanges()  

     ' Find a child in the 'DirectoryEntries' collection which has the   
     ' specified name and type.  
     myEntry2 = myEntries.Find("CN=Sample Entry", myDE.SchemaClassName)  
     Console.WriteLine(myEntry2.Name + " is found in container.")  

     Catch e As Exception  
          Console.WriteLine("The following exception was raised : {0}", e.Message.ToString())  
     End Try  

次の C# の例は、指定したパスで新 DirectoryEntry しいオブジェクトを作成し、コンテナーに新しいエントリを作成して保存する方法を示しています。 新しく作成されたエントリの取得を試みます。

using System;  
using System.DirectoryServices;   

class MyClass1  
{  
   static void Main()  
   {  
      try  
      {          
         DirectoryEntry myEntry1;  
         DirectoryEntry myEntry2;  
         String strPath = "LDAP://DC=fabrikam,DC=com";  

         // Create a 'DirectoryEntry' object with the given path.  
         DirectoryEntry myDE = new DirectoryEntry(strPath);  
         DirectoryEntries myEntries = myDE.Children;  

         // Create a new entry in the container.  
         myEntry1 = myEntries.Add("CN=Sample Entry",myDE.SchemaClassName);  
         // Save changes in the 'Active Directory Domain Services' store.  
         myEntry1.CommitChanges();  

         // Find a child in the 'DirectoryEntries' collection which has the   
         // specified name and type.  
         myEntry2 = myEntries.Find("CN=Sample Entry",myDE.SchemaClassName);  
         Console.WriteLine (myEntry2.Name + " is found in container.");  

      }  
      catch(Exception e)  
      {  
         Console.WriteLine("The following exception was raised : {0}",e.Message);  
      }  
   }  
}  

次の C++ の例では、指定したパスを持つ新しい DirectoryEntry オブジェクトを作成し、コンテナーに新しいエントリを作成して保存します。 新しいエントリの取得を試みます。

#using <mscorlib.dll>  
#using <System.dll>  
#using <System.Directoryservices.dll>  

using namespace System;  
using namespace System::DirectoryServices;   

int main() {  
    try {          
        DirectoryEntry* myEntry1;  
        DirectoryEntry* myEntry2;  
        String* strPath = S"LDAP://DC=fabrikam,DC=com";  

        // Create a 'DirectoryEntry' object with the given path.  
        DirectoryEntry* myDE = new DirectoryEntry(strPath);  
        DirectoryEntries* myEntries = myDE->Children;  

        // Create a new entry in the container.  
        myEntry1 = myEntries->Add(S"CN=Sample Entry", myDE->SchemaClassName);  
        // Save changes in the 'Active Directory Domain Services' store.  
        myEntry1->CommitChanges();  

        // Find a child in the 'DirectoryEntries' collection which has the   
        // specified name and type.  
        myEntry2 = myEntries->Find(S"CN=Sample Entry", myDE->SchemaClassName);  
        Console::WriteLine ("{0} is found in container.", myEntry2->Name);  
    } catch(Exception* e) {  
        Console::WriteLine("The following exception was raised : {0}", e->Message);  
    }  
}  

注釈

一致する結果が見つからない場合は、 DirectoryServicesCOMException エラー コード0x2030を含む がスローされます。

適用対象