sharepoint2010 peopleeditor前后台使用方法笔记

139 篇文章 1 订阅

为了满足特定需求,决定使用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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值