Here is the C# code to check if user exists in Active directory or not :
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName")) { using (UserPrincipal user = UserPrincipal.FindByIdentity(context, "LoginName")) { bool userExists = (user != null); if (userExists) { Console.WriteLine("User exists"); Console.WriteLine(user.EmailAddress); } else { Console.WriteLine("User doesn't exist"); } }
}
cool code :)
ReplyDelete