SearchResult クラス
DirectorySearcher を使用した検索中に返される Active Directory 階層のノードをカプセル化します。
この型のすべてのメンバの一覧については、SearchResult メンバ を参照してください。
System.Object
System.DirectoryServices.SearchResult
Public Class SearchResult
[C#]
public class SearchResult
[C++]
public __gc class SearchResult
[JScript]
public class SearchResult
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
SearchResult のインスタンスは、 DirectoryEntry のインスタンスに非常に似ています。 DirectoryEntry は新しいオブジェクトにアクセスするたびに Active Directory 階層から情報を取得しますが、 SearchResult のデータは DirectorySearcher で実行したクエリが返す SearchResultCollection の中で先に利用できる点が大きな違いです。クエリの DirectorySearcher.PropertiesToLoad プロパティのコレクションで指定したプロパティだけが、 SearchResult で使用できます。
使用例
[Visual Basic, C#, C++] 検索条件を持つ新しい DirectoryEntry を作成し、 FindOne メソッドを使用して検索を実行する例を次に示します。検索結果は GetDirectoryEntry に格納されます。検索結果は後でここから取り出され、解析されます。
Imports System
Imports System.DirectoryServices
Imports Microsoft.VisualBasic
Public Class MySample
Public Shared Sub Main()
Dim myLDAPPath As String = ""
Try
' Create a 'DirectoryEntry' object to search.
Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')")
myLDAPPath = Console.ReadLine()
Dim mySearchRoot As New DirectoryEntry(myLDAPPath)
Dim myDirectorySearcher As New DirectorySearcher(mySearchRoot)
' Get the first entry of the search.
Dim mySearchResult As SearchResult = myDirectorySearcher.FindOne()
If Not (mySearchResult Is Nothing) Then
' Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
Dim myDirectoryEntry As DirectoryEntry = mySearchResult.GetDirectoryEntry()
Console.WriteLine(ControlChars.Newline + "The name of the 'myDirectoryEntry' " + _
"directory entry that corresponds to the " + _
"'mySearchResult' search result is : {0}" + _
ControlChars.Newline, myDirectoryEntry.Name)
Dim mySearchResultPath As String = mySearchResult.Path
Console.WriteLine("The path for the 'mySearchResult' search result is : {0}" + _
ControlChars.Newline, mySearchResultPath)
' Get the properties of the 'mySearchResult'.
Dim myResultPropColl As ResultPropertyCollection
myResultPropColl = mySearchResult.Properties
Console.WriteLine("The properties of the 'mySearchResult' are :")
Dim myKey As String
For Each myKey In myResultPropColl.PropertyNames
Dim tab1 As String = " "
Console.WriteLine(myKey + " = ")
Dim myCollection As Object
For Each myCollection In myResultPropColl(myKey)
Console.WriteLine(tab1 + myCollection)
Next myCollection
Next myKey
Else
Console.WriteLine("The '" + myLDAPPath + "' path not found.")
End If
Catch e As Exception
Console.WriteLine("The '" + myLDAPPath + "' path not found.")
Console.WriteLine("Exception : " & e.Message)
End Try
End Sub 'Main
End Class 'MySample
[C#]
using System;
using System.DirectoryServices;
public class MySample
{
public static void Main()
{
string myLDAPPath = "";
try
{
// Create a 'DirectoryEntry' object to search.
Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')");
myLDAPPath = Console.ReadLine();
DirectoryEntry mySearchRoot = new DirectoryEntry(myLDAPPath);
DirectorySearcher myDirectorySearcher =
new DirectorySearcher(mySearchRoot);
// Get the first entry of the search.
SearchResult mySearchResult = myDirectorySearcher.FindOne();
if ( mySearchResult != null )
{
// Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
DirectoryEntry myDirectoryEntry =
mySearchResult.GetDirectoryEntry();
Console.WriteLine("\nThe name of the 'myDirectoryEntry' " +
"directory entry that corresponds to the " +
"'mySearchResult' search result is : {0}\n",
myDirectoryEntry.Name);
string mySearchResultPath = mySearchResult.Path;
Console.WriteLine("The path for the 'mySearchResult' search "
+ "result is : {0}\n", mySearchResultPath);
// Get the properties of the 'mySearchResult'.
ResultPropertyCollection myResultPropColl;
myResultPropColl = mySearchResult.Properties;
Console.WriteLine("The properties of the " +
"'mySearchResult' are :");
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = " ";
Console.WriteLine(myKey + " = ");
foreach( Object myCollection in myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}
}
else
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
}
}
catch(Exception e)
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
Console.WriteLine("Exception : " + e.Message);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
#using <System.Directoryservices.dll>
using namespace System;
using namespace System::Collections;
using namespace System::DirectoryServices;
int main() {
String* myLDAPPath = S"";
try {
// Create a 'DirectoryEntry' object to search.
Console::WriteLine(S"Enter the path ( Ex : 'LDAP://MyServer')");
myLDAPPath = Console::ReadLine();
DirectoryEntry* mySearchRoot = new DirectoryEntry(myLDAPPath);
DirectorySearcher* myDirectorySearcher = new DirectorySearcher(mySearchRoot);
// Get the first entry of the search.
SearchResult* mySearchResult = myDirectorySearcher->FindOne();
if (mySearchResult) {
// Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
DirectoryEntry* myDirectoryEntry = mySearchResult->GetDirectoryEntry();
Console::WriteLine(
String::Concat(S"\nThe name of the 'myDirectoryEntry' ",
S"directory entry that corresponds to the ",
S"'mySearchResult' search result is : {0}\n"),
myDirectoryEntry->Name);
String* mySearchResultPath = mySearchResult->Path;
Console::WriteLine(S"The path for the 'mySearchResult' search result is : {0}\n", mySearchResultPath);
// Get the properties of the 'mySearchResult'.
ResultPropertyCollection* myResultPropColl = mySearchResult->Properties;
Console::WriteLine(S"The properties of the 'mySearchResult' are :");
IEnumerator* myEnum = myResultPropColl->PropertyNames->GetEnumerator();
while (myEnum->MoveNext()) {
String* myKey = __try_cast<String*>(myEnum->Current);
Console::WriteLine(S"{0} = ", myKey);
IEnumerator* myEnum = myResultPropColl->Item[myKey]->GetEnumerator();
while (myEnum->MoveNext()) {
Console::WriteLine(S"\t{0}", myEnum->Current);
}
}
} else {
Console::WriteLine(S"The '{0}' path not found.", myLDAPPath);
}
} catch (Exception* e) {
Console::WriteLine(S"The '{0}' path not found.", myLDAPPath);
Console::WriteLine(S"Exception : {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.DirectoryServices
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System.Directoryservices (System.Directoryservices.dll 内)
参照
SearchResult メンバ | System.DirectoryServices 名前空間 | DirectoryEntry | DirectoryEntries | PropertyCollection | PropertyValueCollection | DirectorySearcher | ReferralChasingOption | SearchResultCollection | ResultPropertyCollection | ResultPropertyValueCollection | SearchScope | SortDirection | SortOption