sharepoint2010 peopleeditor前后台使用方法笔记

来源:互联网 发布:淘宝保温杯发展趋势 编辑:程序博客网 时间:2024/05/03 18:26

为了满足特定需求,决定使用sharepoint:peopleeditor,用的时候发现他非常强大,在项目中用的和网上找了一些资料记录如下

html

 <%-- 自定义人员类型空间,autopostback="true"允许回发服务器  2013-04-01--%>    <sharepoint:peopleeditor maximumheight="1" autopostback="true" height="25px" width="100px"     rows="1" id="PeopleEditorWorkUserName" runat="server" multiselect="false" placebuttonsunderentityeditor="false"    showerrorplaceholder="true" />

1,简单方法 

public static string GetPeopleEditorValue(PeopleEditor objPeopleEditor)        {            string strResult = string.Empty;            ArrayList list = objPeopleEditor.ResolvedEntities;                        foreach (Microsoft.SharePoint.WebControls.PickerEntity p in list)            {                string userId = p.EntityData["SPUserID"].ToString();                string DisplayName = p.DisplayText.ToString();                strResult += userId + ";#" + DisplayName;                strResult += ",";            }            return strResult;        }
2,炫一下JS
用JavaScript为PeopleEditor控件赋值?function setPeoplePicker(pickerid, value) { var field = $("#" + pickerid); if (field.find('.ms-inputuserfield:visible').length > 0) { // IE浏览器 var userlist = field.find('.ms-inputuserfield').html(); field.find('.ms-inputuserfield').html(userlist+";"+value); field.find('img:first').click(); } else { // FF var userlist = field.find("textarea:first").val(); field.find("textarea:first").val(userlist + ";" + value); } } $(document).ready(function () { setPeoplePicker("<%=PeopleEditorWorkUserName.ClientID%>", "CustomValue");

3,其他项目里用的。 

 List<string> userlist = new List<string>();            #region 得到用户列表            SPWeb web = SPContext.Current.Web;            ArrayList approversArray = pdName.ResolvedEntities;            foreach (PickerEntity entity in approversArray)            {               if (entity.EntityData["PrincipalType"].ToString() == "SharePointGroup")                {                    //如果是组则                    SPGroup group = web.SiteGroups[entity.Key];                    //grouplist.Add(group);                }                else if (entity.EntityData["PrincipalType"].ToString() == "User")                {                    //如果是用户则                    SPUser user = web.EnsureUser(entity.Key);                    userlist.Add(user.LoginName);                    ffApplyName.Value = user;                }            }            foreach (SPGroup g in grouplist)            {                SPUserCollection users = g.Users;                foreach (SPUser u in users)                {                    if (!userlist.Contains(u.LoginName))                    {                        userlist.Add(u.LoginName);                    }                }            }            #endregion

另外一个项目用到的

  /// <summary>        /// 得到人员选择器获得用户信息        /// 可以获得(姓名、登录帐号、ID、邮件、职务等等)        /// </summary>        /// <returns></returns>        string GetAllInfo()        {            string logInName = string.Empty;            string userName = string.Empty;            string userID = string.Empty;                       //SPWeb web = SPContext.Current.Web;            List<string> userlist = new List<string>();            //List<string> userlist = new List<string>();            foreach (PickerEntity mype in PeopleEditorWorkUserName.ResolvedEntities)            {                if (mype.EntityData["PrincipalType"].ToString() == "SharePointGroup")                {                    //如果是组则                    //SPGroup group = web.SiteGroups[mype.Key];                    //grouplist.Add(group);                }                else if (mype.EntityData["PrincipalType"].ToString() == "User")                {                    //如果是用户则                    //SPUser user = web.EnsureUser(mype.Key);                    //userlist.Add(user.LoginName);                    //登录帐号                    logInName = mype.Key;                    //登录名                    userName = mype.DisplayText;                    //ID                    userID = mype.EntityData["SPUserID"].ToString();                    ffApplyName.Value = userID+";#"+userName;                }            }            return logInName;        }


4,为了不避免错误

public string GetPersonInfo(Control control, string ffID){        string strReturn = "";        if (control is PeopleEditor)        {            if (((PeopleEditor)control).Parent.Parent.Parent.ID == ffID)            {                PeopleEditor peopleEditor = ((PeopleEditor)control);                foreach (PickerEntity pe in peopleEditor.ResolvedEntities)                {                    string principalType = pe.EntityData["PrincipalType"].ToString();                    if (principalType == "User" || principalType == "SecurityGroup")                    {                        strReturn = pe.Key;                        break;                    }                }            }        }        else        {            foreach (Control c in control.Controls)            {                strReturn = GetPersonInfo(c, ffID);                if (strReturn != "")                {                    break;                }            }        }        return strReturn; }

5,赋值
public void SetDefaultPerson(Control control, string ffID, string userLoginName) {            string strflag = "";            if (control is PeopleEditor)            {                if (((PeopleEditor)control).Parent.Parent.Parent.ID == ffID)                {                    if ((((PeopleEditor)control).ResolvedEntities.Count < 1))                    {                        PickerEntity entity = new PickerEntity();                        entity.Key = userLoginName;                         System.Collections.ArrayList entityArrayList = new                        System.Collections.ArrayList();                        entityArrayList.Add(entity);                         ((PeopleEditor)control).UpdateEntities(entityArrayList);                        strflag = "TaskOver";                    }                }            }            else            {                foreach (Control c in control.Controls)                {                    SetDefaultPerson(c, ffID, userLoginName);                    if (strflag != "")                    {                        break;                    }                }            }}
手写于  2013-04-07
群:212099235

原创粉丝点击