从人员选择器中取值

/// <summary>
        /// 从人员选择器中取值
        /// </summary>
        /// <param name="peopleEditor"></param>
        /// <returns></returns>
        public static List<SPPrincipal> GetSPPrincipalsFromPeopleEditor(PeopleEditor peopleEditor)
        {
            List<SPPrincipal> rtn = new List<SPPrincipal>();
            SPWeb web = SPContext.Current.Web;
            SPUserCollection users = web.SiteUsers;
            SPGroupCollection groups = web.SiteGroups;
            foreach (PickerEntity pe in peopleEditor.ResolvedEntities)
            {
                string principalType = pe.EntityData["PrincipalType"].ToString();
                if (principalType == "User" || principalType == "SecurityGroup")
                {
                    string loginName = pe.Key;
                    foreach (SPUser u in users)
                    {
                        if (u.LoginName == loginName)
                        {
                            rtn.Add(u);
                            break;
                        }
                    }
                }
                string groupName = pe.Key;
                foreach (SPGroup g in groups)
                {
                    if (g.Name == groupName)
                    {
                        rtn.Add(g);
                        break;
                    }
                }
            }
            return rtn;
        }
posted @ 2011-05-12 14:12  Jason.Bird  阅读(196)  评论(0编辑  收藏  举报