SearchResult クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
SearchResult クラスは、DirectorySearcher を介した検索中に返されるActive Directory Domain Services階層内のノードをカプセル化します。
public ref class SearchResult
public class SearchResult
type SearchResult = class
Public Class SearchResult
- 継承
-
SearchResult
例
次の例では、目的のパスを持つ新しい 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
myDirectoryEntry.Dispose()
mySearchRoot.Dispose()
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
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);
}
}
mySearchRoot.Dispose();
myDirectoryEntry.Dispose();
}
else
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
}
}
catch(Exception e)
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
Console.WriteLine("Exception : " + e.Message);
}
}
}
注釈
SearchResult クラスのインスタンスは、DirectoryEntry クラスのインスタンスとよく似ています。 重要な違いは、DirectoryEntry クラスは新しいオブジェクトにアクセスするたびにActive Directory Domain Services階層から情報を取得しますが、SearchResult のデータは既に SearchResultCollection で使用でき、DirectorySearcher クラスで実行されるクエリから返されます。 クエリの DirectorySearcher.PropertiesToLoad コレクションで指定されたプロパティのみが、 SearchResultから使用できます。
プロパティ
| 名前 | 説明 |
|---|---|
| Path |
この SearchResultのパスを取得します。 |
| Properties |
このオブジェクトのプロパティの ResultPropertyCollection コレクションを取得します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetDirectoryEntry() |
Active Directory Domain Services階層から、DirectoryEntryに対応するSearchResultを取得します。 |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |