How to: Change Profile Properties

Last modified: March 23, 2010

Applies to: SharePoint Server 2010

This code example retrieves and changes three types of profile properties: a core property, a profile type property, and a profile subtype property.

Replace servername and Hobbies with actual values before running the code example. Also add references to the following in your Microsoft Visual Studio project:

  • Microsoft.Office.Server

  • Microsoft.Office.Server.UserProfiles

  • Microsoft.SharePoint

  • System.Web

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;

namespace UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {

            using (SPSite site = new SPSite("http://servername"))
            {
                SPServiceContext context = SPServiceContext.GetContext(site);

 
                ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                ProfileSubtypePropertyManager pspm = ps.Properties;
                ProfileSubtypeProperty p = pspm.GetPropertyByName("Hobbies");
 
                p.CoreProperty.Separator = MultiValueSeparator.Semicolon;
                p.CoreProperty.Commit();
 
                p.TypeProperty.IsVisibleOnViewer = true;
                p.TypeProperty.Commit();
 
                p.PrivacyPolicy = PrivacyPolicy.OptIn;
                p.Commit();
          
            }
        }
    }
}
Show: