sharepoint2010 userprofileManager1

2012-11-29 17:09

sharepoint 获取userprofileManager中用户详细信息

using (SPSite spSite = new SPSite(siteUrl))
            {
                DataTable usersDT = new DataTable();
                //用户名
                usersDT.Columns.Add("UserName", typeof(string));
                //描述
                usersDT.Columns.Add("AboutMe", typeof(string));
                //专业领域
                usersDT.Columns.Add("Responsibility", typeof(string));
                //移动电话
                usersDT.Columns.Add("CellPhone", typeof(string));
                //传真
                usersDT.Columns.Add("Fax", typeof(string));
                //住宅电话
                usersDT.Columns.Add("HomePhone", typeof(string));
                //办公电话
                usersDT.Columns.Add("Office", typeof(string));
                //助手
                usersDT.Columns.Add("Assistant", typeof(string));
                //参与的项目
                usersDT.Columns.Add("PastProjects", typeof(string));
                //技能
                usersDT.Columns.Add("Skills", typeof(string));
                //学校
                usersDT.Columns.Add("School", typeof(string));
                //生日
                usersDT.Columns.Add("Birthday", typeof(string));
                //兴趣
                usersDT.Columns.Add("Interests", typeof(string));
                //公作电子邮件
                usersDT.Columns.Add("WorkEmail", typeof(string));
                //部门
                usersDT.Columns.Add("Department", typeof(string));
                //职务
                usersDT.Columns.Add("Title", typeof(string)); 

                SPServiceContext serviceContext = SPServiceContext.GetContext(spSite);
                //initialize user profile config manager object
                UserProfileManager upm = new UserProfileManager(serviceContext);

                string accountName = "";
                if (Request.QueryString["accountname"] != null)
                {
                    //获取呗查看用户名
                    accountName = Request.QueryString["accountname"].ToString();
                }else{
                    //获取当前登录用户名
                    accountName= SPContext.Current.Web.CurrentUser.LoginName;
                }
                //获取用的详细配置信息
                UserProfile u = upm.GetUserProfile(accountName);
                //创建dataRow实例
                DataRow dr = usersDT.NewRow();
                if (u[PropertyConstants.PictureUrl].Value != null)
                {
                    dr["userImageUrl"] = u[PropertyConstants.PictureUrl].Value.ToString();
                }
                else
                {
                    dr["userImageUrl"] = "/_layouts/images/person.gif";
                }
                dr["userName"] = u[PropertyConstants.FirstName].Value.ToString();
                dr["AboutMe"] = u[PropertyConstants.AboutMe].Value.ToString();
                dr["Responsibility"] = u[PropertyConstants.Responsibility].Value.ToString();
                dr["CellPhone"] = u[PropertyConstants.CellPhone].Value.ToString();
                dr["Fax"] = u[PropertyConstants.Fax].Value.ToString();
                dr["HomePhone"] = u[PropertyConstants.HomePhone].Value.ToString();
                dr["Office"] = u[PropertyConstants.Office].Value.ToString();
                dr["Assistant"] = u[PropertyConstants.Assistant].Value.ToString();
                dr["PastProjects"] = u[PropertyConstants.PastProjects].Value.ToString();
                dr["Skills"] = u[PropertyConstants.Skills].Value.ToString();
                dr["School"] = u[PropertyConstants.School].Value.ToString();
                dr["Birthday"] = u[PropertyConstants.Birthday].Value.ToString();
                dr["Interests"] = u[PropertyConstants.Interests].Value.ToString();
                dr["WorkEmail"] = u[PropertyConstants.WorkEmail].Value.ToString();
                dr["Department"] = u[PropertyConstants.Department].Value.ToString();
                dr["Title"] = u[PropertyConstants.Title].Value.ToString();
                usersDT.Rows.Add(dr);
            }

你可能感兴趣的:(SharePoint)