如何:检索用户配置文件属性

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

适用范围: SharePoint Server 2010

此示例使用用户配置文件对象模型来显示服务器上存在的用户配置文件属性。在运行代码示例之前,请将 servername 替换为实际值。此外,还应在 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));
                //Get the properties
                  ProfileSubtypePropertyManager pspm = ps.Properties;
                    foreach (ProfileSubtypeProperty profileSubtypeProperty in pspm.PropertiesWithSection )
                    {
                           Console.WriteLine(profileSubtypeProperty.Name);
                    }


               }
            }

        }
    }

请参阅

任务

如何:检索用户配置文件

如何:检索两个用户配置文件之间的共同之处

如何:使用更改日志获取最新用户配置文件更改