SharePoint - Updating current users profile property in Server Side Object Model

  1.  string currentUser = SPContext.Current.Web.CurrentUser.LoginName;  
  2.  SPSite currentSite = SPContext.Current.Site;  
  3.   
  4. SPSecurity.RunWithElevatedPrivileges(delegate  
  5.             {  
  6.                 System.Web.HttpContext currentContext = System.Web.HttpContext.Current;  
  7.                 System.Web.HttpContext.Current = null;  
  8.                 try  
  9.                 {  
  10.                     // Set the context of the site to the SPSite site  
  11.                     SPServiceContext context = SPServiceContext.GetContext(currentSite);  
  12.   
  13.                     // Create and instance of the UserProfileManager  
  14.                     UserProfileManager profileManager = new UserProfileManager(context);  
  15.                     UserProfile userProfile = profileManager.GetUserProfile(currentUser);  
  16.                     
  17.                        
  18.                     userProfile["Property Name"].Value = "New property value";  
  19.                     userProfile.Commit();   
  20.                 }  
  21.                 catch (Exception ex)  
  22.                 {  
  23.                   // Handle the exception
  24.                 }  
  25.             });