如何:为多值属性设置多个值

上次修改时间: 2010年1月27日

适用范围: SharePoint Server 2010

Microsoft SharePoint Server 2010 支持多值属性,因此 UserProfile 对象上的 this[] 运算符现在可返回一个名为 UserProfileValueCollection 的 ArrayList。下面的代码示例演示如何将多个值添加到一个多值属性。有关如何创建 PublishedPapers 属性的信息,请参阅如何:创建多值属性

运行该代码示例前,用实际值替换 servername、domainname 和 username。此外,还应在 Microsoft Visual Studio 项目中添加对以下项目的引用:

  • 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("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();              }
        }
    }
}

请参阅

任务

如何:创建多值属性

如何:更改配置文件属性

如何:创建分类多值属性

如何:为用户配置文件属性设置隐私策略