I have an AD search module which works as I want it to; searching for a matching forename and/or surname in the appropriate OU.
I would like to extend it to be more flexible, so that instead of just searching for a matching string in the surname/forename fields it can match partial strings. I already have it applying a star to the end of the filter, which accomplishes part of this, but I would like it to match partial strings at the start as well, with more precision than just a starting wildcard.
Ideally I would like it to match any record where the search term is the start of the word in question, as this will allow multi-part surnames to work without needing to code every possibility.
For example, if the user searches for "zet", it will match a field containing "Zetten" (as the actual filter passed to the DirectorySearch er object is "zet*"), but not my actual name, "van Zetten". I would like it to match my name, but not a record such as "Unzetser", so a double-star search is not suitable.
Another example: If someone searches for "Lad" it should find "bin Laden" and "Ladbroke", but not "Salad".
I think what I need to do can be accomplished with a regular expression of some kind, so it will match any whitespace character (including the start of the field being searched) at the start of the search term, rather than a completely open double-wildcard search such as "*zet*".
But I don't know if the DS.filter property can use a regex at all, and the syntax to use if it can.
I hope that's clear enough; I can try to elaborate if necessary.
6 15945
I think you can try something like this. The filter uses LDAP and you can't replace it with a regex:
(|(name=Zen*)(n ame= Zen*)))
That seems like a good alternative method, although it doesn't appear to work. I think it's better than my original idea though.
Removing the pipe and searching just for - (sn= " + strSurname + "*)
alone (that is, with the space) works in exactly the same way as
(without the space) so it's not very useful.
I also tried inserting single quotes around the string (including the space) but that just broke it and stopped it from returning any results at all.
It's acting like the filter object just applies a Trim() (or equivalent) to the terms, but I don't know if that's really how it's working. If it is, can it be overridden?
Plater 7,872
Recognized Expert Expert
Can you use SQL syntax and say "sn like ' Zet*'" with the single quotes? perhaps it won't do single quotes with the =?
Frinavale 9,735
Recognized Expert Moderator Expert
Can you use SQL syntax and say "sn like ' Zet*'" with the single quotes? perhaps it won't do single quotes with the =?
I was thinking along the same lines...but was wondering if LINQ might be appropriate.
-Frinny
Plater 7,872
Recognized Expert Expert
Actually I was thinking that if last name was "van Zetten" then you would want the merger of ("Z*" | "* Z*"), in which case the ' ' will not be ignored
Sorry for the delay in getting back to the thread.
I'm afraid you've lost me now. Using SQL would be slightly more familiar to me, but I was under the impression that the DS.filter has its own specific syntax. Am I wrong about that? If so, how would I go about using the "sn LIKE xxx" syntax?
What is LINQ and how would that help me? I've looked it up briefly, and I think it seems to answer my question a couple of lines above, although I could be mistaken. Is it that the DS.filter has its own syntax in LINQ, which is converted to the appropriate query language/syntax based on the directory type the DirectorySearch er object is attached to?
Even if I'm right about that, I still have no idea how to actually use it to my advantage though!
Edit: Okay, I feel a bit stupid here, but I just got it working based on that very last bit. Sticking the extra star in the query with a space is working, so it's trying to match (sn=* " + strSurname + "*).
Thanks all :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Edwin G. Castro |
last post by:
Hi,
I'm new to XSLT and I'm having a hard time figuring out whether XSLT
will do what I need it to do.
I have a XML file with a whole bunch of <message> elements. These
<message> elements have <!]> in them. I would like to use
XSLT to remove the <message> elements whose CDATA (the "...") matches
a particular regular expression.
|
by: Dave |
last post by:
Hi
All C# ADSI samples that I run cause unspecified errors. If I
translate them into VB.NET they run fine.
Here's an example:
public string getEmail(string LDAPPath, string username)
{
DirectoryEntry entry = new DirectoryEntry(LDAPPath);
|
by: cameron |
last post by:
I have always been under the impression that LDAP was optimized for
speed. Fast queries, fast access, slower writes. I have a block of data
in LDAP and in SQL. Exact same data. The query is fast but the first
access to the result set takes longer that to do the query in SQL and
process the sql results.
From my trace.axd
LDAP Test Starting Search 0.000112 0.000043
LDAP Test Done Search 0.003821 0.003374 <--- fast query at .003 sec
LDAP...
|
by: Jay |
last post by:
I need to add a parameter to a directorysearcher.filter rather than using
hard-coded text. I have the following code that finds all members of an AD
group and then for each of those results tries to find that users
samAccountName.
Perhaps I'm going about this incorrectly but I know if I could pass my
searcher.filter a paramter rather than typing "cn=jason", etc this code
would work, any help would be very much appreciated!:
'Get all...
|
by: Anonieko Ramos |
last post by:
Answer. Use IHttpHandler.
thanks Ro ry for coming up with this code.
It processes css file to add variables. neat idea
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
| |
by: Xavier |
last post by:
hello,
in a string which i read from a textfile there are some lines, which must be
eliminated.
The content of the stringvariable is for example :
myString="
--comment 1
Update .....
--comment 2 .......
|
by: mike |
last post by:
I'm needing a bit of help to fine tune my Filter property for a
DirectorySearcher. My context here is for a company phone directory. A
user enters the string they want to search for (in txtSearch) and hits
the Fire button.
The problem is that this picks up disabled accounts which I'd rather
didn't happen. I basically grabbed this string straight from somewhere
but don't really know what "anr " means.
ds.Filter = "(&(anr=" &...
|
by: LiQuick |
last post by:
Dear Reader,
When I try to run the following LDAP filter with the DirectorySearcher
it doesn't return any OU's but when I use it with Active Directory
Users and Computers it returns the desired results:
(&(ou>="")(name=ICTS*))
Furthermore if I use the following Filter the DirectorySearcher
retrieves all OU's:
|
by: Jim in Arizona |
last post by:
I'm trying to do a check to see if a specific active directory user account
exists in active directory AND a specific group. I can't seem to get the
filter down right.
I can do this to find a matching name in active directory:
================================================
Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://my.domain.local")
Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
Dim oresult As...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |