1

I facing a problem while retrieving the list data from SharePoint online. I have list items around 20,000. I am using a caml query to retrieve the data based on conditions in dotnet csom. it has 5300 items however I am getting complete 20,000 items see the below code. I have used below logic to over come the list view threshold limit.

 var list = web.Lists.GetByTitle("ListName");
 CamlQuery camlQuery = new CamlQuery();
 camlQuery.ViewXml = "<View><RowLimit>3000</RowLimit><Where><Or><Eq><FieldRef Name='AccountRecordType' /><Value Type='Text'>Institution</Value></Eq><And><Eq><FieldRef Name='AccountRecordType' /><Value Type='Text'>Group</Value></Eq><Neq><FieldRef Name='MemberStatus' /><Value Type='Text'>Member</Value></Neq></And></Or></Where></View>";
 List<ListItem> lstListItemCollection = new List<ListItem>();

                do
                {
                    ListItemCollection listItemCollection = list.GetItems(camlQuery);
                    clientContext.Load(listItemCollection);
                    clientContext.ExecuteQuery();

                    //Adding the current set of ListItems in our single buffer
                    lstListItemCollection.AddRange(listItemCollection);
                    //Reset the current pagination info
                    camlQuery.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition;

                } while (camlQuery.ListItemCollectionPosition != null);



                foreach (ListItem listItem in lstListItemCollection)
                {

                }

2 Answers 2

1

You are missing the Query attribute. In CSOM, we need to use Query in CAML.

Try your CAML query as below:

camlQuery.ViewXml = "<View><RowLimit>3000</RowLimit><Query><Where><Or><Eq><FieldRef Name='AccountRecordType' /><Value Type='Text'>Institution</Value></Eq><And><Eq><FieldRef Name='AccountRecordType' /><Value Type='Text'>Group</Value></Eq><Neq><FieldRef Name='MemberStatus' /><Value Type='Text'>Member</Value></Neq></And></Or></Where></Query></View>";
3
  • Thanks to find out the missing query text. however Now I am getting List view threshold exception while retrieving the data Commented Apr 17, 2017 at 7:12
  • Are those columns indexed ? Try decreasing the Rowlimit to 100. Also check out these links - sharepoint.stackexchange.com/a/177593/8068 and codeproject.com/Articles/1076854/… , Commented Apr 17, 2017 at 7:17
  • I have kept Indexed columns before inserting the data to into list. reduced the row limit to 100 and even 50 in caml query. but still giving the same issue. any help ? Commented Apr 18, 2017 at 10:05
-1

Text field :

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>test</Value></Eq></Where></Query><RowLimit>50</RowLimit></View>";

Date time field :

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Start_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>2017-12-21T00:00:00Z</Value></Eq></Where></Query><RowLimit>50</RowLimit></View>";

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.