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)
                {

                }
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>";
-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, privacy policy and cookie policy

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