SharePoint 2013 User Profile (用户配置文件)

环境:Windows Server 2012,SharePoint 2013,Visual Studio 2013


User Profile Service Application(管理配置文件服务),准确的说是SharePoint上的User Profile Service Application,本文主要介绍怎么在SharePoint中开启User Profile Service Application、管理User Profile Service Application以及怎么在代码中读取用户配置文件的信息。


1、User Profile Service Application 所在位置
这里写图片描述

2、新建User Profile Service Application:点击新建按钮,选择User Profile Service Application,新建页面需要填一些参数,看着填就行,问题不大;建完后点击User Profile Service Application名称可以进入管理界面
这里写图片描述

3、管理配置文件服务,这里面有很多东西,用得着的自己看一下
这里写图片描述

4、管理用户属性 :管理用户配置文件的属性,如:姓名、部门、职务等
这里写图片描述

5、管理用户配置文件:进去后根据用户名找到用户配置文件,点击用户名就可以看到操作了
这里写图片描述

6、在代码中读取用户用户配置文件,例:读取用户部门

        /// <summary>
        /// 根据AD账号获取部门
        /// </summary>
        /// <param name="userValue"></param>
        /// <returns>部门名称</returns>
        public static string GetDepartment(SPFieldUserValue userValue)
        {
            string Department = "";
            SPServiceContext myContext = SPServiceContext.GetContext(SPContext.Current.Site);
            try
            {
                UserProfileManager myProfile = new UserProfileManager(myContext);
                UserProfile user = myProfile.GetUserProfile(userValue.User.LoginName);

                if (user != null)
                {
                    Department = user["Department"].Value + "";
                }
            }
            catch (Exception ex)
            {
                CommonLog.WriteLog("获取用户部门【GetDepartment】出现异常:" + ex.Message + "\n\r" + ex.StackTrace);
            }
            return Department;
        }

完了,好像想说点啥,但好像啥也不想说。。。