如何:检索用户配置文件
此代码示例演示如何使用用户配置文件对象模型来检索用户配置文件数据。
运行本代码示例之前,用实际的值替换 domainname、username 和电话号码 ( nnnnnnnnnn )。此外,还应在 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 profileManager = new UserProfileManager(context);
string sAccount = "domainname\\username";
UserProfile u = profileManager.GetUserProfile(sAccount);
//Updates values
u[PropertyConstants.HomePhone].Value = "nnnnnnnnnn";
u[PropertyConstants.CellPhone].Value = "nnnnnnnnnn";
//commits changes
u.Commit();
}
}
}
}