1
Answer

Set the Company property of a user using dotnet 3.5

pem pem

pem pem

14y
4.6k
1
Hi guys

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 :


          
   Dim u As New UserPrincipal(SharedObjects.PrincipalContext)


u.Surname = ln
u.SamAccountName = login
u.EmailAddress = email
u.Name = ln
u.DisplayName = fn & " " & ln
u.Enabled = True

Dim 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
Answers (1)