How to: Set Multiple Values to a Multivalue Property
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
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"))
{
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(); }
}
}
}
See Also
Tasks
How to: Create Multivalue Properties
How to: Change Profile Properties