Export (0) Print
Expand All

How to: Set Multiple Values to a Multivalue Property

Last modified: January 27, 2010

Applies to: SharePoint Server 2010

Microsoft SharePoint Server 2010 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.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 UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://servername"))
            {
                SPServiceContext context =
                    SPServiceContext.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();              }
        }
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft