首页 > 其他 > 详细

SharePoint 2013 更新多个用户字段(Person or Group)

时间:2015-09-15 16:29:33      阅读:239      评论:0      收藏:0      [点我收藏+]

有时我们需要更新一个用户到Person or Group类型的字段, 当然这个属性允许设置多个用户, 要如何才能添加新的用户到该字段,同时还不影响原始存在的值。

这里我们需要了解 SPFieldUserValueCollection类, 该类是包含user字段的所有值,而SPFieldUserValue继承了SPFieldLookupVlaue.

 1 // 获取List
 2 SPListItemCollection BGProfileCollection = SPContext.Current.Web.Lists[CSTListType.BGProfileListName].Items;
 3 
 4 // 根据条件去获取需要更新的某一条数据
 5 SPListItem BGProfileListItem = BGProfileCollection.OfType<SPListItem>().Where(a => a.GetLookupField<int>(ConstVariables.AllBGProfileColumns.ColumnBGName, 0, 0) == Convert.ToInt32(this.ddl_BGNameList.SelectedItem.Value))..FirstOrDefault();
 6 
 7 // 获取该条数据user字段的值
 8 SPFieldUserValueCollection values = (SPFieldUserValueCollection)BGProfileListItem ["MultiUser"];
 9 
10 //添加用户到该集合, 这里我使用当前用户
11 values.Add(new SPFieldUserValue(SPContext.Current.Site.OpenWeb(), SPContext.Current.Web.CurrentUser.ID, SPContext.Current.Web.CurrentUser.Name));
12 
13 // 更新该字段的值
14 BGProfileListItem["MultiUser"] = values;
15 BGProfileListItem.Update();

 

SharePoint 2013 更新多个用户字段(Person or Group)

原文:http://www.cnblogs.com/mystar/p/4810474.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!