1

I trying to search my organization Active directory for users.

If the FirstName or LastName or DisplayName matches a particular string value, it should return the users.

My Code:

// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.GivenName = "Ramesh*";
// qbeUser.Surname = "Ramesh*";
// qbeUser.DisplayName= "Ramesh*";    

PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach(var found in srch.FindAll())
{
    //
}

The problem is that I am able to search by only one filter.

I am able to AND the filters but not OR. Whether any solutions are available?

Ramesh Durai
  • 2,666
  • 9
  • 32
  • 55
  • 1
    See [a possible solution for this issue here](http://stackoverflow.com/questions/3195124/ambiguous-name-resolution-anr-ma-equivalent-in-net-3-5-directoryservices-ac) - using the extensibility of `UserPrincipal` to get access to the `anr` property (ambiguous name resolution) which allows searches in multiple name-related properties – marc_s Aug 30 '13 at 15:35
  • @marc_s: Thanks for the solution. It's working correctly. Can you post this as a answer. So that I can accept it? – Ramesh Durai Aug 30 '13 at 15:50

2 Answers2

2

See a possible solution for this issue in this other SO question.

You will need to use the extensibility of UserPrincipal to create a descendant class, in order to get access to the anr property (anr = ambiguous name resolution) which allows searches in multiple name-related properties at once.

Community
  • 1
  • 1
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • This link(http://msdn.microsoft.com/en-us/library/cc223243.aspx) helped me the find more about Ambiguous Name Resolution(ANR). – Ramesh Durai Aug 30 '13 at 16:14
0

Have a look at the DirectorySearcher. This article may help.

KMarron
  • 503
  • 1
  • 6
  • 15