1

I want to create LDAP query to filter printers by name and location and model

deSearch.Filter = String.Format("(&(&(&(&(objectCategory=printQueue)(printername={0}))(location={1}))(driverName={2})))", queueName, location, modelNumber);

I create this but it didn't run correctly

  1. The first problem is to search by all search criteria together
  2. if one of criteria is empty or null ,I set it by * to get all results .Is it correct ?

All ideas are welcomed

2 Answers 2

3

You only need one & operator. They are n-ary, not binary, operators in LDAP filter expressions:

(&(objectCategory=printQueue)(printername={0})(location={1})(driverName={2}))

(RFC 2254 defines what follows the & (or |) as a SET OF Filter, not as exactly two filters. This is about the only good reason I can see why they chose that ghastly prefix notation.)

I would personally supply 'printQueue' as an argument as well in a query like this.

'*' will match any attribute value, but it requires the attribute to be actually present, i.e. for the objectClass to have such an attribute.

Sign up to request clarification or add additional context in comments.

Comments

0

Accoroding to EJP reply I created the code for that here

 StringBuilder filter=new StringBuilder("(&(objectClass=printQueue)");
        if (!string.IsNullOrEmpty(queueName))
            filter.Append("(printerName=*"+queueName+"*)") ;

        if (!string.IsNullOrEmpty(location))

            filter.Append("(location=*" + location + "*)");

        if (!string.IsNullOrEmpty(modelNumber))

            filter.Append("(driverName=*" + modelNumber + "*)");

        filter.Append(")");

        deSearch.Filter = filter.ToString();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.