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

Search() public static method

Synchronously perfoms the search specified by the Ldap URL, using the specified search constraints (such as the maximum number of entries to find or the maximum time to wait for search results). When this method is called, a new connection is created automatically, using the host and port specified in the URL. After all search results have been received from the server, the method closes the connection (in other words, it disconnects from the Ldap server). As part of the search constraints, a choice can be made as to whether to have the results delivered all at once or in smaller batches. If 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 static Search ( LdapUrl toGet, LdapSearchConstraints cons ) : LdapSearchResults
toGet LdapUrl Ldap URL specifying the entry to read. /// ///
cons LdapSearchConstraints The constraints specific to the search. /// ///
return LdapSearchResults
        public static LdapSearchResults Search(LdapUrl toGet, LdapSearchConstraints cons)
        {
            LdapConnection lconn = new LdapConnection();
            lconn.Connect(toGet.Host, toGet.Port);
            if (cons == null)
            {
                // This is a clone, so we already have our own copy
                cons = lconn.SearchConstraints;
            }
            else
            {
                // get our own copy of user's constraints because we modify it
                cons = (LdapSearchConstraints) cons.Clone();
            }
            cons.BatchSize = 0; // Must wait until all results arrive
            LdapSearchResults toReturn = lconn.Search(toGet.getDN(), toGet.Scope, toGet.Filter, toGet.AttributeArray, false, cons);
            lconn.Disconnect();
            return toReturn;
        }

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 ( 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