Share via


How to: Create and Edit a User Profile Property

User profile properties are name-value pairs attached to user profiles that describe personal information about the user. The profile store contains a list of user profile property information. This information is obtained by importing it from a directory that contains user accounts or manually by typing the account information into the user profile store. By default, Microsoft Office SharePoint Server 2007 can import from the Active Directory directory service, LDAP servers, and Business Data Catalog.

Office SharePoint Server 2007 offers several property improvements for developers building solutions using the user profile store. For more information, see User Profile Properties Overview.

Office SharePoint Server 2007 provides a default set of commonly used user profile properties. Sometimes these may not be sufficient, and you might need additional properties. In such cases, you can create new properties, and they will be available for all user profiles. The following code example shows you how to add a new user profile property to the default set of properties and how to set privacy policies for the new property.

Replace servername with an actual value before using the code example. Also add references to the following in your Microsoft Visual Studio project:

  • Microsoft.Office.Server

  • Microsoft.SharePoint

  • System.Web

Example

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 UserProfilesOMApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Code example adds a new property called Marital Status.
            using (SPSite site = new SPSite("https://servername"))
            {
                ServerContext context =
                    ServerContext.GetContext(site);
                UserProfileManager profileManager = new
                    UserProfileManager(context);
                try
                {
                    //Get the properties
                    PropertyCollection pc = profileManager.Properties;
                    Property p = pc.Create(false);
                    p.Name = "MaritalStatus";
                    p.DisplayName = "Marital Status";
                    p.Type = "String";
                    p.Length = 100;
                    p.PrivacyPolicy = PrivacyPolicy.OptIn;
                    p.DefaultPrivacy = Privacy.Organization;
                    pc.Add(p);
                }
                catch (DuplicateEntryException e)
                {
                    Console.WriteLine(e.Message);
                    Console.Read();
                }
                catch (System.Exception e2)
                {
                    Console.WriteLine(e2.Message);
                    Console.Read();
                }
            }
        }
    }
}

See Also

Tasks

How to: Create User Profiles in the User Profile Store
How to: Create and Edit a User Profile Property
How to: Create Multivalue Properties
How to: Set Multiple Values to a Multivalue Property
How to: Change the Default Separator Character for Entering Multivalue Properties
How to: Create Properties with Choice Lists
How to: Set Privacy Policies for User Profile Properties