How to: Create Multivalue Properties

How to: Create Multivalue Properties

Last modified: March 22, 2010

Applies to: SharePoint Server 2010

Properties now support multiple values. There are many scenarios in which this improvement can be useful; for example, when defining properties that usually contain multiple values, such as a user’s interests and areas of expertise.

The IsMultiValued parameter in the object model indicates whether the property is a multivalue property or not. However, just like the property data type, this parameter is not modifiable, once it is set.

The object model returns the multiple values of a multivalue property as an ArrayList object. The order of the values in the collection is the same as the update order. For an example, see How to: Set Multiple Values to a Multivalue Property.

Multivalue properties are also indexable. Currently, SharePoint Enterprise Search in SharePoint Server 2010 supports Contains and Equals clauses for multivalue properties.

Note that SharePoint Server 2010 allows you to map a multivalue property at the connection source to a single-value portal property. When you import properties, the import operation tries to get the first value from the source.

The following code example shows you how to create multivalue properties. If you use this example, replace servername with an actual value. 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 UserProfilesOMApp
    class Program
        static void Main(string[] args)
            //Code example adds a new property called Published Papers.
            using (SPSite site = new SPSite("http://servername"))
                SPServiceContext context = SPServiceContext.GetContext(site);
                UserProfileConfigManager upcm = new UserProfileConfigManager(context);

                    ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

                    // create core property
                    CorePropertyManager cpm = ppm.GetCoreProperties();
                    CoreProperty cp = cpm.Create(false);
                    cp.Name = "Published Papers";
                    cp.DisplayName = "Published Papers";
                    cp.Type = PropertyDataType.StringMultiValue;
                    cp.Length = 100;
                    cp.IsMultivalued = true;

                    // create profile type property
                    ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
                    ProfileTypeProperty ptp = ptpm.Create(cp);
                    ptp.IsVisibleOnEditor = true;
                    ptp.IsVisibleOnViewer = true;

                    // create profile subtype property
                    ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                    ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                    ProfileSubtypePropertyManager pspm = ps.Properties;
                    ProfileSubtypeProperty psp = pspm.Create(ptp);

                    psp.IsUserEditable = true;
                    psp.PrivacyPolicy = PrivacyPolicy.OptIn;
                    psp.DefaultPrivacy = Privacy.Organization;

                catch (DuplicateEntryException e)
                catch (System.Exception e2)
© 2016 Microsoft