I have been unable to set up the company property of a user using the dot 3.5 way. Here is the bit of code I use :
VB.NET
Dim u AsNew UserPrincipal(SharedObjects.PrincipalContext)
u.Surname = ln
u.SamAccountName = login
u.EmailAddress = email
u.Name = ln
u.DisplayName = fn & " " & ln
u.Enabled = TrueDim context As PrincipalContext = New PrincipalContext(ContextType.Domain, SharedObjects.LDAPName(), "OU=Users,OU=" & My.Settings.OUName & "," & SharedObjects.LDAP_DomainName(), SharedObjects.UserLogin(), SharedObjects.UserPassword())
u.Save(context)
'THIS IS THE TRICK!Dim de As DirectoryEntry
de = DirectCast(u.GetUnderlyingObject(), DirectoryEntry)
de.Properties("Company").Value = entity
de.CommitChanges()
Actually I am creatinf a user (using UserPrincipal, principalContext, etc) but if I want to set up the company name for this user, the only way I found to archive this is using the old 2.0 way with DirectoryEntry. IT WORKS but I don't like it.
Is there a better way to do that ?
cheers mates
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Michael Liben8 reputationPosted Feb 27, 2010, 3:01 AM EST