problems with < and > operators using DirectorySearcher

  • Thread starter Thread starter Mario Rodriguez
  • Start date Start date
M

Mario Rodriguez

Hi, I'm having big problems trying to include the < and > operator,
specifying the Filter property of the DirectorySearcher object.

For example, if the filter is :

string strFilter = "(&(objectCategory=user)(sAMAccountName<=bortiz))";



The query is executed successfully, but if the query is:

string strFilter = "(&(objectCategory=user)(sAMAccountName<bortiz))";



the following exception is raised:



{"The (&(objectCategory=user)(sAMAccountName<bortiz)) search filter is
invalid." } System.Exception



Any idea how to fix it?



thanks
 
Hi said:
specifying the Filter property of the DirectorySearcher object.

For example, if the filter is :
string strFilter = "(&(objectCategory=user)(sAMAccountName<=bortiz))";

The query is executed successfully, but if the query is:

string strFilter = "(&(objectCategory=user)(sAMAccountName<bortiz))";

the following exception is raised:

{"The (&(objectCategory=user)(sAMAccountName<bortiz)) search filter is
invalid." } System.Exception

According to the LDAP filter syntax RFC, the LDAP filter syntax DOES
NOT support > and < - it only supports >= and <=

Check it out at (http://www.ietf.org/rfc/rfc2254.txt), section 4:

"4. String Search Filter Definition

The string representation of an LDAP search filter is defined by
the
following grammar, following the ABNF notation defined in [5]. The
filter format uses a prefix notation.

filter = "(" filtercomp ")"
filtercomp = and / or / not / item
and = "&" filterlist
or = "|" filterlist
not = "!" filter
filterlist = 1*filter
item = simple / present / substring / extensible
simple = attr filtertype value
filtertype = equal / approx / greater / less
equal = "="
approx = "~="
greater = ">="
less = "<="
extensible = attr [":dn"] [":" matchingrule] ":=" value
/ [":dn"] ":" matchingrule ":=" value
present = attr "=*"
substring = attr "=" [initial] any [final]
initial = value
any = "*" *(value "*")
final = value
attr = AttributeDescription from Section 4.1.5 of [1]
matchingrule = MatchingRuleId from Section 4.1.9 of [1]
value = AttributeValue from Section 4.1.6 of [1]

The attr, matchingrule, and value constructs are as described in the
corresponding section of [1] given above.
"

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
I see, sorry for my confusion, but I tried do it because the information
provided in this page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDirectoryServicesDirectorySearcherClassFilterTopic.asp

where explicitly says that you CAN use the < and > operators to built the
Filter

This is definitely a documentation bug - Microsoft has logged it and
will fix it.

This page for instance is correct in *NOT* telling you about the < and
operators which are not allowed in LDAP queries:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/search_filter_syntax.asp

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top