Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

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("http://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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.