Share via


How to: Set Multiple Values to a Multivalue Property

Microsoft Office SharePoint Server 2007 supports multivalue properties, and therefore, the this[] operator on the UserProfile object now returns an ArrayList called UserProfileValueCollection. The following code example shows you how to add multiple values to a multivalue property. For information on how to create the PublishedPapers property, see How to: Create Multivalue Properties.

Replace servername, domainname, and username with actual values before running 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 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);
                UserProfile profile =
                  profileManager.GetUserProfile("domainname\\username");
                    profile["PublishedPapers"].Add((Object)"a@b.com");
                    profile["PublishedPapers"].Add((Object)"c@d.com");
                    profile.Commit();              }
        }
    }
}

See Also

Tasks

How to: Create Multivalue Properties
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