using Microsoft.Office.Server; using Microsoft.Office.Server.UserProfiles; using (SPSite site = new SPSite("http://sitecollectionurl")) { //User profile manager object holds the complete profile store UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(site)); //UserProfile object holds the acount specific userprofile UserProfile userProfile = profileManager.GetUserProfile("domain\\administrator"); //OTB property name can be assigned as below using PropertyConstants class userProfile[PropertyConstants.FirstName].Value = "My first name"; //Custom property value can be assigned as below by hardcoding the property name userProfile["CustomPropertyName"].Value = "Test Value"; userProfile.Commit(); }
Loop through all the user profiles available in SSP profile store.
UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(site)); foreach(UserProfile userProfile in profileManager) { if(null != userProfile[PropertyConstants.FirstName].value) lblFirstName.Text = userProfile[PropertyConstants.FirstName].value; if(null != userProfile["CustomPropertyName"].value) lblCustomPropertyValue.Text = userProfile["CustomPropertyName"].value; }
I get this error when trying to assign values to the properties:
ReplyDeleteProperty Not Editable: This property can not be modified.