Monday, April 7, 2008

Setting multivalue properties in User profile

More on User profiles; MOSS 2007 supports multivalue properties in the User profiles, but how do you set these fields? The this[] operator on the UserProfile object returns an ArrayList called UserProfileValueCollection. This code example shows you how to add multiple values to a multivalue property:

Add references to Microsoft.Office.Server, Microsoft.SharePoint and System.Web in your Microsoft Visual Studio project.

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 UserProfilesDemoApp

{

class UserProfileProgram

{

static void Main(string[] args)

{

using (SPSite site = new SPSite("http://servername"))

{

ServerContext serverContext = ServerContext.GetContext(site);

UserProfileManager userProfileManager = new UserProfileManager(context);

UserProfile userProfile = userProfileManager.GetUserProfile("domainname\\username");


// Insert your database access code here to get the values to set!


userProfile["MyInterests"].Add((Object)"Soccer");

userProfile["MyInterests"].Add((Object)"Icehockey");

userProfile.Commit(); }

}

}

}
}

© Copyright 2008, Tomas Elfving

0 kommentarer: