Initializes a new instance of the UserPrincipal class by using the specified context.
Namespace:
System.DirectoryServices.AccountManagement
Assembly:
System.DirectoryServices.AccountManagement (in System.DirectoryServices.AccountManagement.dll)
Visual Basic (Declaration)
Public Sub New ( _
context As PrincipalContext _
)
Dim context As PrincipalContext
Dim instance As New UserPrincipal(context)
public UserPrincipal(
PrincipalContext context
)
public:
UserPrincipal(
PrincipalContext^ context
)
public function UserPrincipal(
context : PrincipalContext
)
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 = "jimdaly@fabrikam.com";
usr.SetPassword("securelyStoredPassword");
usr.Save();
usr.Dispose();
ctx.Dispose();
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5
Reference
Other Resources