如何从Sharepoint 2013用户组中获取自定义列值 [英] How to Fetch custom column value from Sharepoint 2013 user group
本文介绍了如何从Sharepoint 2013用户组中获取自定义列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI伙计
我在SP 2013中创建了一个用户组,我从列表设置中添加了一个自定义列,
如何使用客户端对象模型获取自定义列值。
我需要一次获取该组的所有用户。
Peoplemanager将消耗更多时间因为它必须遍历每个用户。
有什么办法吗?请分享你的答案。
解决方案
这里你使用这段代码片段
public void GetSPUsersOfGroup( string webURL, int groupId)
{
List< spuser> listSPUsers = new List< spuser>();
Web currentWeb = ClientContext.Site.OpenWeb(webURL);
UserCollection userCollection = currentWeb.SiteGroups.GetById(groupId).Users; // 对于SharePoint 2010,它只接受groupId。
// 对于SharePoint 2013,您可以传递groupName并获取数据。
ClientContext.Load(userCollection) );
ClientContext.ExecuteQuery();
foreach (用户用户 userCollection)
{
SPUser spUser = new SPUser();
spUser.DisplayName = user.Title;
spUser.Id = user.Id;
spUser.Email = user.Email;
spUser.AccountName = user.LoginName;
// spUser.CustomColName = user.CustomColumnName;
listSPUsers.Add( spUser);
}
}
我知道了
CamlQuery camlquery = new CamlQuery();
camlquery.ViewXml =< 查看 > < ViewFields > < FieldRef 名称 =' Your_Custom_Column />< / ViewFields>< /视图>;
我们需要在caml查询中添加自定义字段名称,然后执行此
clientContext.Web.SiteUserInfoList.GetItems(camlquery);
HI Folks
I have created an user group in SP 2013 and i have added one custom column to it, from the list settings,
How to get the custom column value using Client side object model.
I need to fetch all the users of that group at once.
Peoplemanager will consume more time as it has to iterate over each user.
Is there any way ? Please share your answers.
解决方案
Here you go with this code snippet
public void GetSPUsersOfGroup(string webURL, int groupId) { List<spuser> listSPUsers = new List<spuser>(); Web currentWeb = ClientContext.Site.OpenWeb(webURL); UserCollection userCollection = currentWeb.SiteGroups.GetById(groupId).Users; //For SharePoint 2010 it accepts only groupId. //For SharePoint 2013 you can pass groupName and fetch data. ClientContext.Load(userCollection); ClientContext.ExecuteQuery(); foreach (User user in userCollection) { SPUser spUser = new SPUser(); spUser.DisplayName = user.Title; spUser.Id = user.Id; spUser.Email = user.Email; spUser.AccountName = user.LoginName; // spUser.CustomColName = user.CustomColumnName; listSPUsers.Add(spUser); } }
I got it
CamlQuery camlquery = new CamlQuery(); camlquery.ViewXml = "<View> <ViewFields><FieldRef Name='Your_Custom_Column/></ ViewFields></View>"; We need to add the custom fields name in the caml query and just execute this
clientContext.Web.SiteUserInfoList.GetItems(camlquery);
这篇关于如何从Sharepoint 2013用户组中获取自定义列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文