How to: Create Multivalue Properties

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, Enterprise Search in Microsoft Office SharePoint Server 2007 supports Contains and Equals clauses for multivalue properties.

Note that Office SharePoint Server 2007 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.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 UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {

            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 = "PublishedPapers";
                    p.DisplayName = "Published Papers";
                    p.Type = "string";
                    p.IsMultivalued = true;
                    p.IsUserEditable = true;
                    p.IsVisibleOnEditor = true;
                    p.IsVisibleOnViewer = true;
                    p.DefaultPrivacy = Privacy.Public;
                    p.PrivacyPolicy = PrivacyPolicy.OptIn;
                    pc.Add(p);                }
                catch (DuplicateEntryException e)
                {
                    Console.WriteLine(e.ToString());
                }
                catch (System.Exception e2)
                {
                    Console.WriteLine(e2.ToString());
                }
            }
        }
    }
}

See Also

Tasks

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