Check UserID exists in Active Directory
Please
add the
System.DirectoryServices.AccountManagement
namespace and assembly to your
code.
public string DoesUserExist(string userName)
{
using (var domainContext = new PrincipalContext(ContextType.Domain,
"spl"))
{
using (var foundUser =
UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName,
userName))
{
if (foundUser != null)
return foundUser.Name;
else
return "User Does not exist
";
}
} }
Comments