如何:创建和编辑用户配置文件属性

用户配置文件属性是附加到用于描述用户个人信息的用户配置文件的名称值对。配置文件存储中包含用户配置文件属性信息的列表。该信息是通过从包含用户帐户的目录进行导入或手动向用户配置文件存储中键入帐户信息来获取的。默认情况下,Microsoft Office SharePoint Server 2007 可从 Active Directory 目录服务、LDAP 服务器和业务数据目录进行导入。

Office SharePoint Server 2007 中提供了几项属性改进,可供通过用户配置文件存储构建解决方案的开发人员使用。有关详细信息,请参阅用户配置文件属性概述

Office SharePoint Server 2007 提供了一组默认的常用用户配置文件属性。有时这些属性会不够用,您可能需要其他属性。这种情况下可以创建新属性,并且可用于所有用户配置文件。以下代码示例将向您演示如何向默认属性集添加新的用户配置文件,以及如何设置新属性的隐私策略。

使用代码示例之前,请用实际的值替换 servername。另外在 Microsoft Visual Studio 项目中添加以下引用:

  • Microsoft.Office.Server

  • 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 UserProfilesOMApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Code example adds a new property called Marital Status.
            using (SPSite site = new SPSite("https://servername"))
            {
                ServerContext context =
                    ServerContext.GetContext(site);
                UserProfileManager profileManager = new
                    UserProfileManager(context);
                try
                {
                    //Get the properties
                    PropertyCollection pc = profileManager.Properties;
                    Property p = pc.Create(false);
                    p.Name = "MaritalStatus";
                    p.DisplayName = "Marital Status";
                    p.Type = "String";
                    p.Length = 100;
                    p.PrivacyPolicy = PrivacyPolicy.OptIn;
                    p.DefaultPrivacy = Privacy.Organization;
                    pc.Add(p);
                }
                catch (DuplicateEntryException e)
                {
                    Console.WriteLine(e.Message);
                    Console.Read();
                }
                catch (System.Exception e2)
                {
                    Console.WriteLine(e2.Message);
                    Console.Read();
                }
            }
        }
    }
}

See Also

任务

如何:在用户配置文件存储中创建用户配置文件

如何:创建和编辑用户配置文件属性

如何:创建多值属性

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

如何:更改用于输入多值属性的默认分隔符

如何:创建包含选项列表的属性

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