LDAP Client.Net

Client.Search Method (String, String, Scope, StringCollection)

Search the directory. Has no timeout. Does not ignore the size limit error. For a complete description of search syntax, see RFC 1558: A String Representation of LDAP Search Filters (http://www.faqs.org/rfcs/rfc1558.html).

[Visual Basic]
Public Function Search( _ 
   ByVal base As String, _ 
   ByVal filter As String, _ 
   ByVal scope As Scope, _ 
   ByVal attributeNames As StringCollection _ 
) As EntryCollection
[C#]
public EntryCollection Search(
   string base,
   string filter,
   Scope scope,
   StringCollection attributeNames
);
[C++]
public: EntryCollection* Search(
   String* base,
   String* filter,
   Scope scope,
   StringCollection* attributeNames
);
[JScript]
public function Search(
   String base,
   String filter,
   Scope scope,
   StringCollection attributeNames
): EntryCollection;

Parameters

base
Base DN.
filter
Search filter.
scope
Search scope.
attributeNames
Names of desired attributes.

Return Value

Collection of entries matching the search query.

Example

[C#]
using System;
using System.Collections.Specialized;
using LdapServices.Ldap;

namespace LDAPSampleCodeConsole
{
class SampleApp
{
static void Main(string[] args)
{
Client client = new Client();

// Connect to the directory
client.Connect("directory.yourCompany.ca");

// Search the directory for entries with surname starting with 'Ab'
EntryCollection entries;
StringCollection attributes = new StringCollection();
attributes.Add("cn");
entries = client.Search("o=yourCompany,c=ca", "sn=Ab*", Scope.SubTree, attributes);

// Display the result counts
Console.WriteLine("Count: " + entries.Count);
Console.WriteLine("Attribute Count: " + entries[0].Attributes.Count);

// Disconnect
client.Disconnect();
}
}
}

See Also

Client Class | LdapServices.Ldap Namespace | Client.Search Overload List