Writing values to a Moss2007 user profile

August 28, 2008   9:14


It took me quite some time to figure out how to write information to a SharePoint user profile. The web seemed only full of examples about how to read information from profiles. At the MSDN site there is an example, but they are using the UserProfileService web service.

At the end it turned out to be very simple to update the values in a user profile: just update the value in the property and then do a Commit on the profile.

using (SPSite site = new SPSite(”http://sharepointsite”))
{
 UserProfileManager uPMgr =
 new UserProfileManager(ServerContext.GetContext(site));
 UserProfile profile = uPMgr.GetUserProfile(”Administrator”);
 profile["WorkEmail"].Value = “newemail@address.com”;
 profile.Commit();
}
Tags: , , , .









The content expressed in this blog are those of Edwin Vriethoff and do not represent his employer's view in anyway. The contents of this blog has been carefully put together, but Edwin Vriethoff is not responsible in any way for any direct or indirect harm caused by individuals or organizations using the content of this blog in any way.