Novell.Directory.Ldap.LdapConnection.Search C# (CSharp) Method

Search() public method

Asynchronously performs the search specified by the parameters, also allowing specification of constraints for the search (such as the maximum number of entries to find or the maximum time to wait for search results).
LdapException A general exception which includes an error /// message and an Ldap error code. ///
public Search ( System base_Renamed, int scope, System filter, System attrs, bool typesOnly, LdapSearchQueue queue, LdapSearchConstraints cons ) : LdapSearchQueue
base_Renamed System
scope int The scope of the entries to search. The following /// are the valid options: ///
    ///
  • SCOPE_BASE - searches only the base DN
  • /// ///
  • SCOPE_ONE - searches only entries under the base DN
  • /// ///
  • SCOPE_SUB - searches the base DN and all entries /// within its subtree
  • ///
///
filter System The search filter specifying the search criteria. /// ///
attrs System The names of attributes to retrieve. /// ///
typesOnly bool If true, returns the names but not the values of /// the attributes found. If false, returns the /// names and values for attributes found. /// ///
queue LdapSearchQueue The queue for messages returned from a server in /// response to this request. If it is null, a /// queue object is created internally. /// ///
cons LdapSearchConstraints The constraints specific to the search. /// ///
return LdapSearchQueue
        public virtual LdapSearchQueue Search(System.String base_Renamed, int scope, System.String filter, System.String[] attrs, bool typesOnly, LdapSearchQueue queue, LdapSearchConstraints cons)
        {
            if ((System.Object) filter == null)
            {
                filter = "objectclass=*";
            }
            if (cons == null)
                cons = defSearchCons;

            LdapMessage msg = new LdapSearchRequest(base_Renamed, scope, filter, attrs, cons.Dereference, cons.MaxResults, cons.ServerTimeLimit, typesOnly, cons.getControls());
            MessageAgent agent;
            LdapSearchQueue myqueue = queue;
            if (myqueue == null)
            {
                agent = new MessageAgent();
                myqueue = new LdapSearchQueue(agent);
            }
            else
            {
                agent = queue.MessageAgent;
            }

            try
            {
                agent.sendMessage(conn, msg, cons.TimeLimit, myqueue, null);
            }
            catch (LdapException lex)
            {
                throw lex;
            }
            return myqueue;
        }

Same methods

LdapConnection::Search ( System base_Renamed, int scope, System filter, System attrs, bool typesOnly, LdapSearchQueue queue ) : LdapSearchQueue
LdapConnection::Search ( LdapUrl toGet ) : LdapSearchResults
LdapConnection::Search ( LdapUrl toGet, LdapSearchConstraints cons ) : LdapSearchResults
LdapConnection::Search ( System base_Renamed, int scope, System filter, System attrs, bool typesOnly ) : LdapSearchResults
LdapConnection::Search ( System base_Renamed, int scope, System filter, System attrs, bool typesOnly, LdapSearchConstraints cons ) : LdapSearchResults

Usage Example

Example #1
2
    // read and print search results
    public static bool searchDynamicGroupEntry( LdapConnection lc,
        String searchBase)
    {
        bool status = true;
        int searchScope = LdapConnection.SCOPE_BASE;
        String[] attrList = new String[]{"member"};
        String searchFilter = "(objectclass=*)";

        /* Since reading members of a dynamic group could potentially involve
         * a significant directory search, we use a timeout. Setting
         * time out to 10 seconds
         */
        LdapSearchConstraints cons = new LdapSearchConstraints();
        cons.TimeLimit = 10000 ;

        try
        {
            LdapSearchResults searchResults =
                lc.Search(  searchBase,
                searchScope,
                searchFilter,
                attrList,          // return only "member" attr
                false,             // return attrs and values
                cons );            // time out value

            LdapEntry nextEntry = null ;
            // Read and print search results.  We expect only one entry */
            if (( nextEntry = searchResults.next()) != null )
            {
                LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
                IEnumerator allAttributes = attributeSet.GetEnumerator();

                if ( allAttributes.MoveNext() )
                {
                    // found member(s) in this group
                    LdapAttribute attribute =
                        (LdapAttribute)allAttributes.Current;
                    String attributeName = attribute.Name;

                    IEnumerator allValues = attribute.StringValues;

                    if( allValues != null)
                    {
                        while(allValues.MoveNext())
                        {
                            String Value = (String) allValues.Current;
                            Console.WriteLine("            " + attributeName
                                       + " : " + Value);
                        }
                    }
                }
                else
                {
                    // no member(s) found in this group
                    Console.WriteLine("            No objects matched the "
                               + " memberQueryURL filter.\n  ");
                }
            }
        }
        catch( LdapException e )
        {
            Console.WriteLine( "Error: " + e.ToString() );
            status = false;
        }
        return status;
    }
All Usage Examples Of Novell.Directory.Ldap.LdapConnection::Search