question

TD123 avatar image
0 Votes"
TD123 asked RaytheonXie-MSFT commented

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


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.


office-sharepoint-onlineoffice-sharepoint-server-developmentsharepoint-devoffice-sharepoint-server-customizationoffice-sharepoint-server-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered RaytheonXie-MSFT commented

Hi @TD123 ,
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.


· 12
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi @RaytheonXie-MSFT

I tried above, but no luck - the error did not change. The query works fine when less than 5k items.
My issue is I have more then 10k. If you execute above query with 10k, with camlQuery.FolderServerRelativeUrl provided, you might face issue :)

0 Votes 0 ·

Hi @TD123 ,
Per my test, I found we can set folder via FileDirRef property and remove camlQuery.FolderServerRelativeUrl.

 camlQuery.ViewXml = @"<View Scope='Recursive'><Query><OrderBy Override='TRUE'><FieldRef Name='Modified' Ascending='False'/></OrderBy><where><Eq><FieldRef Name='FileDirRef' /><Value Type='File'>/TestDoc/Test</Value></Eq></where></Query><RowLimit Paged='TRUE'>10</RowLimit></View>";
 ListItemCollection listItems = oList.GetItems(camlQuery);

The similar issue for refer:
https://stackoverflow.com/questions/36137351/calmquery-rowlimit-not-working


0 Votes 0 ·
TD123 avatar image TD123 RaytheonXie-MSFT ·

Hi @RaytheonXie-MSFT

Still no luck. I tried both options. As we discussed, these queries works fine when we have less than 5k items but the issue only occurs when we have more.

just to summarize issue, or replicating it,

  1. Document library with more that 5k+ items(increased threshold limit)

  2. Query folder specific URL - to get recent 10 documents(modified desc) within entire folder hierarchie - <View Scope='Recursive'> to get only files.




0 Votes 0 ·
Show more comments
SiyaKhumalo-1787 avatar image
0 Votes"
SiyaKhumalo-1787 answered TD123 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SiyaKhumalo-1787 we can't set this because we are on SharePoint Online.

0 Votes 0 ·