SearchResult Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
La classe SearchResult encapsule un nœud dans la hiérarchie services de domaine Active Directory retournée lors d’une recherche via DirectorySearcher.
public ref class SearchResult
public class SearchResult
type SearchResult = class
Public Class SearchResult
- Héritage
-
SearchResult
Exemples
L’exemple suivant crée un DirectoryEntry objet avec le chemin souhaité et utilise la FindOne méthode pour lancer la recherche. Après avoir effectué la recherche, l’exemple utilise la GetDirectoryEntry méthode pour récupérer l’entrée de répertoire en direct identifiée dans les résultats de la recherche.
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);
}
}
}
Remarques
Les instances de la SearchResult classe sont très similaires aux instances de DirectoryEntry classe. La différence cruciale est que la classe DirectoryEntry récupère ses informations à partir de la hiérarchie services de domaine Active Directory chaque fois qu’un nouvel objet est accessible, tandis que les données de SearchResult sont déjà disponibles dans le SearchResultCollection, où elle est retournée à partir d’une requête effectuée avec la classe DirectorySearcher. Seules les propriétés spécifiées par le biais de la DirectorySearcher.PropertiesToLoad collection dans votre requête seront disponibles à partir de SearchResult.
Propriétés
| Nom | Description |
|---|---|
| Path |
Obtient le chemin d’accès de ce SearchResultfichier . |
| Properties |
Obtient une ResultPropertyCollection collection de propriétés pour cet objet. |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetDirectoryEntry() |
Récupère le DirectoryEntry qui correspond à la SearchResult à partir de la hiérarchie services de domaine Active Directory. |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |