UserPrincipal Constructor (PrincipalContext)
Initializes a new instance of the UserPrincipal class by using the specified context.
Assembly: System.DirectoryServices.AccountManagement (in System.DirectoryServices.AccountManagement.dll)
The user principal account is not persisted when it is created. To save the account, call the Save method.
The following code example connects to the LDAP domain "fabrikam.com" with the username and password initialized in the PrincipalContext constructor to "administrator" and "securelyStoredPassword."
The properties set in the example, such as user name and e-mail address, are created under the container specified in the PrincipalContext constructor: "CN=Users,DC=fabrikam,DC=com."
PrincipalContext ctx = new PrincipalContext( ContextType.Domain, "fabrikam.com", "CN=Users,DC=fabrikam,DC=com", "administrator", "securelyStoredPassword"); UserPrincipal usr = new UserPrincipal(ctx); usr.Name = "Jim Daly"; usr.Description = "This is the user account for Jim Daly"; usr.EmailAddress = "email@example.com"; usr.SetPassword("securelyStoredPassword"); usr.Save(); usr.Dispose(); ctx.Dispose();
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.