How can we check whether the USERID exists in Active Directory or not.
I have LDAP String and UserID, can I find whether that UserID exists in Active Directory or no
I would use the System.DirectoryServices.AccountManagement namespace.
string UserID = "grhm";
bool userExists = false;
using (var ctx = new PrincipalContext(ContextType.Domain))
{
using (var user = UserPrincipal.FindByIdentity(ctx, UserID))
{
if (user != null)
{
userExists = true;
user.Dispose();
}
}
}
See http://msdn.microsoft.com/en-us/library/bb344891.aspx for more info