如何:更改配置文件属性

上次修改时间: 2010年3月23日

适用范围: SharePoint Server 2010

此代码示例检索和更改三类配置文件属性:核心属性、配置文件类型属性和配置文件子类型属性。

运行此代码示例之前,将 servername 和 Hobbies 替换为实际值。此外,还应在 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);

 
                ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                ProfileSubtypePropertyManager pspm = ps.Properties;
                ProfileSubtypeProperty p = pspm.GetPropertyByName("Hobbies");
 
                p.CoreProperty.Separator = MultiValueSeparator.Semicolon;
                p.CoreProperty.Commit();
 
                p.TypeProperty.IsVisibleOnViewer = true;
                p.TypeProperty.Commit();
 
                p.PrivacyPolicy = PrivacyPolicy.OptIn;
                p.Commit();
          
            }
        }
    }
}

请参阅

任务

如何:创建多值属性

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

如何:创建分类多值属性

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