如何:检索用户配置文件属性
此代码示例使用用户配置文件对象模型显示服务器上存在的用户配置文件属性。运行代码示例之前,请将 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 UserProfilesApp
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://servername"))
{
ServerContext context =
ServerContext.GetContext(site);
UserProfileManager m_mngr = new UserProfileManager(context);
//Get the properties
PropertyCollection props = m_mngr.Properties;
foreach (Property prop in props)
{
Console.WriteLine(prop.Name);
}
}
}
}
}