SharePoint Online --- Document library with 10k items --- Get latest 10(recent 10 modified from specific folder)

Tarak Dave 21 Reputation points
2021-08-23T11:15:10.027+00:00

I am following this thred

But I am getting "The attempted operation is prohibited because it exceeds the list view threshold". Basically, I want to get the latest 10 modified documents from specific folder of the document library. So I am using below CAML viewXML

camlQuery.ViewXml = @"<View Scope='Recursive'><Query><OrderBy Override='TRUE'><FieldRef Name='Modified' Ascending='False'/></OrderBy></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Modified' /><FieldRef Name='FileDirRef' /><FieldRef Name='FileLeafRef' /></ViewFields><RowLimit Paged='TRUE'>10</RowLimit></View>";
camlQuery.FolderServerRelativeUrl = "/clients/account/Account_Demo";

As soon as I specify "Modified" in Order by - this quey throws an error of list view threshold.

Just to share Modified is indexed column

If I remove <FieldRef Name='Modified' Ascending='False'/> from Order By then query works fine but does not serve the purpose of the latest 10.

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,227 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,680 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,674 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,575 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 31,526 Reputation points Microsoft Vendor
    2021-08-24T07:28:59.337+00:00

    Hi @Tarak Dave ,
    Per my test, The ViewFields tag should be in Query tag. Try following CamlQuery:

    camlQuery.ViewXml = "<View Scope='Recursive'><Query><OrderBy Override='TRUE'><FieldRef Name='Modified' Ascending='False'/></OrderBy><ViewFields><FieldRef Name='Title' /><FieldRef Name='Modified' /><FieldRef Name='FileDirRef' /><FieldRef Name='FileLeafRef' /></ViewFields></Query><RowLimit Paged='TRUE'>10</RowLimit></View>";  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Siya Khumalo 1 Reputation point
    2021-08-23T23:13:46.257+00:00

    You can set the list view thresholds on Central Admin.

    Navigate to url: http://server-name:port/_admin/WebApplicationList.aspx
    Click on General Settings, select Resource Throttling.