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- sharepoint2010 peopleeditor前后台使用方法笔记
- angular前后台通讯-笔记(1)
- asp.net下linkbutton的前后台使用方法
- LifrRay Portlet前后台参数和方法调用的笔记
- 个人笔记-jquery 树形下拉框,赋前后台代码
- 前后台代码调用
- ajax前后台调用
- json前后台交互
- symbian前后台切换
- 前后台交互方式
- 前后台系统
- IOS 前后台切换
- 前后台相互调用
- 前后台相关应用
- 前后台转换
- Android 前后台判断
- .net 前后台交互
- EXTJs前后台交互
- Google新文献电邮通知功能
- VS2010中VC9.0Runtime与VC10.0Runtime在win7上装不上提示error code 1603
- Visual Studio + VA 常用快捷键
- ImageView.ScaleType设置图解
- 实战:oracle 分区交换-归档数据
- sharepoint2010 peopleeditor前后台使用方法笔记
- 彻底卸载MySQL
- 服务器返回状态码
- oracle resize报错,dba_segments与dba_data_files中相差很大
- Android属性之build.prop生成过程分析
- POJ-2287-Tian Ji -- The Horse Racing
- 佳能(中国)风光题材的拍摄效果例和要领介绍。
- 利用webqq协议使用python登录qq发消息
- string转换为char*