string currentUser = SPContext.Current.Web.CurrentUser.LoginName;
SPSite currentSite = SPContext.Current.Site;
SPSecurity.RunWithElevatedPrivileges(delegate
{
System.Web.HttpContext currentContext = System.Web.HttpContext.Current;
System.Web.HttpContext.Current = null;
try
{
// Set the context of the site to the SPSite site
SPServiceContext context = SPServiceContext.GetContext(currentSite);
// Create and instance of the UserProfileManager
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile userProfile = profileManager.GetUserProfile(currentUser);
userProfile["Property Name"].Value = "New property value";
userProfile.Commit();
}
catch (Exception ex)
{
// Handle the exception
}
});This code is for updating the current users profile property using Server Side Object Model.
