Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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.
Posted

Here you go with this code snippet
C#
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);
 }
}
 
Share this answer
 
v3
Comments
Karthik_Mahalingam 10-Mar-15 6:11am    
Hi Kushal
// spUser.CustomColName = user.CustomColumnName;
user is not a dynamic object , so it wont work..
Karthik_Mahalingam 30-Apr-15 10:46am    
thanks for your solution.
I got it

XML
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  

C#
clientContext.Web.SiteUserInfoList.GetItems(camlquery);
 
Share this answer
 
Comments
KaushalJB 10-Mar-15 7:06am    
Yeah probably CamlQuery is the best option !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900