1

I am trying to do a GroupBy on a bunch of items that I have retrieved using CSOM and when I try do a foreach loop to go through them I get method not supported exception.

List contactsList = context.Web.Lists.GetByTitle("Contacts List");
CamlQuery contactsQuery = CamlQuery.CreateAllItemsQuery(5000, new []{"ID", "Full_x0020_Name"});
ListItemCollection contactItemsCollection = contactsList.GetItems(contactsQuery);
context.Load(contactItemsCollection);
context.ExecuteQuery();

and then group them

IQueryable<IGrouping<object, ListItem>> groupItems = contactItemsCollection.Where(i => i.FieldValues["Full_x0020_Name"] != null).GroupBy(item => item.FieldValues["Full_x0020_Name"]);

and then when I try to iterate through them

foreach (var groupItem in groupItems)
{
}

System.NotSupportedException was unhandled
  HResult=-2146233067
  Message=Specified method is not supported.
  Source=Microsoft.SharePoint.Client.Runtime

Regards.

1

1 Answer 1

2

This error occurs since in SharePoint 2010 CSOM (V14) Where and GroupBy operators are not supported.

Solution

Replace the line:

IQueryable<IGrouping<object, ListItem>> groupItems = contactItemsCollection.Where(i => i.FieldValues["Full_x0020_Name"] != null).GroupBy(item => item.FieldValues["Full_x0020_Name"]);

with this one:

IEnumerable<IGrouping<object, ListItem>> groupItems = contactItemsCollection.ToList().Where(i => i.FieldValues["Full_x0020_Name"] != null).GroupBy(item => item.FieldValues["Full_x0020_Name"]);
1
  • hi Vadim, am looking for csom c, how to check for duplicates in my SPO environment.. how to get those duplicate listitems..
    – samolpp2
    Apr 27, 2018 at 21:03

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.