2

Unable to get all property of SharePoint group using CSOM.

GroupCollection collGroup = clientx.Web.SiteGroups;
clientx.Load(collGroup, grups => grups.Include(grup => grup.Title, grup => grup.Description, grup => grup.Owner, grup => grup.OnlyAllowMembersViewMembership, grup => grup.AllowMembersEditMembership, grup => grup.AutoAcceptRequestToJoinLeave, grup => grup.AllowRequestToJoinLeave, grup => grup.OwnerTitle, grup => grup.RequestToJoinLeaveEmailSetting, grup => grup.Id, grup => grup.LoginName));

clientx.ExecuteQuery();

Is there any way to fetch all possible property of site group?

I want to do it by Managed code(CSOM), not by Server side or JSOM or REST.

WebService is also preferable.

2 Answers 2

4

I tried your code and got an unknown error. So i tried removing each field in the LINQ query and I found the error is due to grup => grup.Owner. I have changed it to grup => grup.OwnerTitle and the code worked fine. Also for getting each property value of a group loop the group collection object and get its value as per below code.

GroupCollection collGroup = oClientContext.Web.SiteGroups;
oClientContext.Load(collGroup, grups => grups.Include(grup => grup.Title, grup => grup.Description, grup => grup.OwnerTitle, grup => grup.OnlyAllowMembersViewMembership, grup => grup.AllowMembersEditMembership, grup => grup.AutoAcceptRequestToJoinLeave, grup => grup.AllowRequestToJoinLeave, grup => grup.OwnerTitle, grup => grup.RequestToJoinLeaveEmailSetting, grup => grup.Id, grup => grup.LoginName));
oClientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.Group oGroup in collGroup)
{
    oClientContext.Load(oGroup);
    oClientContext.ExecuteQuery();
}
4
  • Welcome. If the answer helped you, mark it as answer. Commented Jun 6, 2016 at 5:45
  • Hi nagarajan, today I tried with grup => grup.Owner and its working. I think problem is something else.
    – Anil Pal
    Commented Jun 8, 2016 at 8:00
  • Thats great. Mark it as answer then. Commented Jun 8, 2016 at 8:02
  • Is there any way to get owner also?
    – Anil Pal
    Commented Jun 8, 2016 at 12:00
2

grup.Owner returns Principal object. so you can't load it using LINQ. You can load owner object for group inside foreach loop like this.

   `   GroupCollection collGroup = context.Web.SiteGroups;
       context.Load(collGroup);
             context.Load(collGroup, grups => grups.Include(grup => grup.Title, grup => grup.Description, grup => grup.OwnerTitle, grup => grup.OnlyAllowMembersViewMembership, grup => grup.AllowMembersEditMembership, grup => grup.AutoAcceptRequestToJoinLeave, grup => grup.AllowRequestToJoinLeave, grup => grup.OwnerTitle, grup => grup.RequestToJoinLeaveEmailSetting, grup => grup.Id, grup => grup.LoginName));
             context.ExecuteQuery();
            foreach(Group g in collGroup)
            {
                Principal temp = g.Owner;
                context.Load(temp, t => t.LoginName, t => t.PrincipalType, t => t.Id);
                context.ExecuteQuery();
                Console.WriteLine(temp.Id);
                Console.WriteLine(temp.LoginName);
                Console.WriteLine(temp.PrincipalType);
            }`

or You can specifically load properties of owner in the GroupCollection LINQ itself like this:

context.Load(collGroup, grups => grups.Include(grup => grup.Title, grup => grup.Owner.PrincipalType, grup => grup.Owner.LoginName, grup => grup.Owner.Id);

Hope this helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.