Tasks that cause excessive server load (such as those involving all list items) are currently prohibited

Viewed 41

We have an Azure Web App, written in C#, that saves PDFs to our SharePoint Documents site. I have put an index on a few columns as suggested by Microsoft. I made sure there were no sorting, grouping, or totals on the library settings. I have added a caml query to limit rows and to order by the indexed column. I have also tried to use a where clause in the loadquery() call and an include statement I load() call to include the indexed column. I have copied and pasted code off the web and cannot get it to not give me the above error. I did find a PowerShell script that did much of what I did in the C# program and it worked. Sadly there are no C# programmers here any longer and I am stuck with trying to blunder my way through. See below the code I am trying to use:

Web rootWeb = context.Web;
var query = context.LoadQuery(rootWeb.Lists.Where(p => p.Title == "Documents")); 
context.ExecuteQuery();
List list = query.FirstOrDefault();

CamlQuery cquery = new CamlQuery();
cquery.ViewXml = @"
    <View Scope='RecursiveAll'>
        <Query>
    
            <OrderBy Override='TRUE'>
                <FieldRef Name='Title' Ascending='TRUE' />
            </OrderBy>
        </Query>
        <RowLimit Paged='TRUE'>4</RowLimit>
    </View>";
ListItemCollection collListItem = list.GetItems(cquery);
context.Load(collListItem, items => items.Include(item => item.Title));
context.ExecuteQuery(); # <--- Of course this is where the error occurs.

I have been working on this for days and cannot figure out what I am NOT doing. Any help would be greatly appreciated. Also what I believe it is trying to get is a list of our folders and not items, not sure if that matters.

1 Answers

So, because I was getting Folders and not files I had to change the CAML query to filter by "FileLeafRef" then I had to get the item as a folder and create it if necessary. Here is part of the code I used to fix the over-the-threshold error.

CamlQuery cquery = new CamlQuery();
cquery.ViewXml =  "<View><ViewFields><FieldRef Name='Title'/></ViewFields><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='String'>" + loanID.ToString() + "</Value></Eq></Where> < OrderBy Override= 'TRUE' >< FieldRef Name = 'Title' Ascending = 'TRUE' /></ OrderBy ></ Query >< RowLimit Paged='TRUE'>2</RowLimit></View>";
ListItemCollection collListItem = list.GetItems(cquery);
context.ExecuteQuery();
Folder folder;


if (collListItem.Count != 0 )
{ 
folder = rootWeb.GetFolderByServerRelativeUrl(folderName);
context.Load(folder);
context.ExecuteQuery();
}
Related