AD searches using LIKE

G

Guest

Hi guys

I'm allowing users to search my SQL database for Projects created by a
certain user. The user login stuff is all stored in AD.

Atm, I can get it to work so that if they type the full name "Dan Nash" for
example, it returns all the Projects I created.

However, it's a tad long-winded.

What I'd like to do is enable them to search for "Dan" and it find all my
projects, as well as any projects by other Dans.

I'm using the DisplayName property to get the samaccountname to search the
database with. Is there a way to do a LIKE type search on displayname?

Here's my current code...

private string PullADUserFromDisplayName(string displayName)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" +
ConfigurationSettings.AppSettings.Get("System_ActiveDirPath"));
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(displayname=" + displayName + "))";
SearchResult resEnt = mySearcher.FindOne();
try
{
return resEnt.Properties["samaccountname"][0].ToString();
}
catch
{
return "null";
}
}

Any help appreciated.

Cheers


Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top