Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm running a small piece of code that populates a drop down from an LDAP query. It checks if the givenname OR the surname start with the letter that is input. e.g.

S would return sarah or smith
SM would return just smith

but not if the Job title = leaver

The code works fine, except if I want to add a not to the query

This works :-

osearcher.Filter = "(|(givenname=" & Label1.Text.ToString & "*)(sn=" & Label1.Text.ToString & "*))"


But this doesn't :-

osearcher.Filter = "(|(givenname=" & Label1.Text.ToString & "*)(sn=" & Label1.Text.ToString & "*))(!(title=leaver))"




I get a "The Directory Service is unavailable" error

Any ideas ? I'm only using the LDAP Job Title field to exclude a certain OU

What I have tried:

I cut and pasted the query into an active directory custom search and it worked fine

(e.g. the result looks like this
(|(givenName=a*)(sn=a*))(!(title=leaver))
Posted
Updated 13-Jun-17 21:34pm

1 solution

Ugh just as I submitted I fixed it :)

Seems like with vb.net you need to start the query with an ampersand e.g.

osearcher.Filter = "(&(|(givenname=" & Label1.Text.ToString & "*)(sn=" & Label1.Text.ToString & "*))(!(title=leaver)))"
 
Share this answer
 
Comments
Richard Deeming 14-Jun-17 16:58pm    
Not just VB.NET - it seems to be the standard syntax from RFC2254.
Search Filter Syntax (Windows)[^]

I suspect the custom search is silently wrapping the conditions in an (&...) to be "helpful". :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900