Friday, February 25, 2011

How to update User profile property using Object Model

User profiles are just repositories for information about individual people. We can programmatically update the properties of user profiles. You just need to specify the account you want to update the property.

Here is the fun part: the code :)

using(SPSite site = new SPSite(http://Site_URL/))
{
     using(SPWeb web = site.OpenWeb())
       {
            ServerContext context = ServerContext.GetContext(site);
         UserProfileManager profMgr = new UserProfileManager(context);
         string acc = @"domaniname\loginname";
         UserProfile profile = profMgr.GetUserProfile(acc);
         profile["AboutMe"].Value = (String.IsNullOrEmpty(txtPropValue.Text)) ? "property_value" : txtPropValue.Text;
         profile.Commit();
      }
}



Happy Coding!!!

No comments:

Post a Comment