1

I am querying a large list and it works well if I don't put any condition in where clause.

I am trying to get items greater than some ID(actual requirement is to get items Created > Today()), as soon as I introduce this condition the query fails with below error :

Additional information: The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.

ListItemCollectionPosition itemPosition = null;
                while(true)
                {
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ListItemCollectionPosition = itemPosition;
                    camlQuery.ViewXml = "<View Scope='RecursiveAll'>"+
                                    "<Query>" +
                                       "<Where>" +
                                          "<Gt>" +
                                            "<FieldRef Name='ID' />" +
                                            "<Value Type='Counter'>80000</Value>" +
                                         "</Gt>" +
                                       "</Where>" +
                                       "</Query>" +     
                                        "<ViewFields>"+
                                         "<FieldRef Name='ID'/>" +
                                         "<FieldRef Name='Created'/>" +
                                         "<FieldRef Name='SRNumber'/>" +
                                         "<FieldRef Name='Name'/>" +
                                         "<FieldRef Name='RequestID'/>" +
                                         "<FieldRef Name='Path'/>" +
                                         "<FieldRef Name='AttachmentType'/>" +
                                        "</ViewFields><RowLimit>100</RowLimit></View>";
                    ListItemCollection collListItem = library.GetItems(camlQuery);
                    clientContext.Load(collListItem);
                    clientContext.ExecuteQuery();
                    itemPosition = collListItem.ListItemCollectionPosition;

                    foreach (ListItem item in collListItem)
                    {

                        if (item.FileSystemObjectType.ToString() == "File")
                        {
                        }
                    }
                    if (itemPosition == null)
                    {
                        break;
                    }

As per my understanding, I can only use the indexed columns in order to query large list and ID is an indexed column so why it doesn't work?

0

Most likely the issue occurs when we use RecursiveAll. Just curious: do you have many subfolders?

Also, try adding

<OrderBy Override='TRUE'><FieldRef Name='ID' />

before your <Where>

  • Thanks Denis. Yes there are may subfolders and the above mentioned suggestion is not working. The query should look like this ? "<View Scope='RecursiveAll'><Query><OrderBy Override='TRUE'><FieldRef Name='ID' />" +"<Where>" – Ishan Dec 3 '18 at 10:06

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.