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

Search() public method

Synchronously performs the search specified by the parameters, using the specified search constraints (such as the maximum number of entries to find or the maximum time to wait for search results). As part of the search constraints, the method allows specifying whether or not the results are to be delivered all at once or in smaller batches. If specified that the results are to be delivered in smaller batches, each iteration blocks only until the next batch of results is returned.
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, LdapSearchConstraints cons ) : LdapSearchResults
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. /// ///
cons LdapSearchConstraints The constraints specific to the search. /// ///
return LdapSearchResults
        public virtual LdapSearchResults Search(System.String base_Renamed, int scope, System.String filter, System.String[] attrs, bool typesOnly, LdapSearchConstraints cons)
        {
            LdapSearchQueue queue = Search(base_Renamed, scope, filter, attrs, typesOnly, null, cons);

            if (cons == null)
                cons = defSearchCons;
            return new LdapSearchResults(this, queue, cons);
        }

Same methods

LdapConnection::Search ( System base_Renamed, int scope, System filter, System attrs, bool typesOnly, LdapSearchQueue queue ) : LdapSearchQueue
LdapConnection::Search ( System base_Renamed, int scope, System filter, System attrs, bool typesOnly, LdapSearchQueue queue, LdapSearchConstraints cons ) : 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

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