I have a SPO list with 30000 list items. I need to query the items in the list based on some of the single line of text
type fields. Below is the code to do that
public List<Microsoft.SharePoint.Client.ListItem> GetListItemsBatch(string listName, string query = "")
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
List listResult = _context.Web.Lists.GetByTitle(listName);
CamlQuery camlQuery = new CamlQuery { ViewXml = query };
//Creating a single buffer for storing all the ListItems
List<Microsoft.SharePoint.Client.ListItem> lstListItemCollection = new List<Microsoft.SharePoint.Client.ListItem>();
do
{
Microsoft.SharePoint.Client.ListItemCollection result = listResult.GetItems(camlQuery);
_context.Load(result);
_context.ExecuteQuery();
//Adding the current set of ListItems in our single buffer
lstListItemCollection.AddRange(result);
//Reset the current pagination info
camlQuery.ListItemCollectionPosition = result.ListItemCollectionPosition;
} while (camlQuery.ListItemCollectionPosition != null);
return lstListItemCollection;
}
string query = $"<View Scope='RecursiveAll'>" +
$"<Query>" +
$"<Where>" +
$"<And>" +
$"<Eq>" +
$"<FieldRef Name='ContactNumber'/>" +
$"<Value Type='Text'>{item.ContactNumber}</Value>" +
$"</Eq>" +
$"<Eq>" +
$"<FieldRef Name='Email' />" +
$"<Value Type='Text'>{item.Email}</Value>" +
$"</Eq>" +
$"<Eq>" +
$"<FieldRef Name='ProjectCode' />" +
$"<Value Type='Text'>{item.ProjectCode}</Value>" +
$"</Eq>" +
$"<Eq>" +
$"<FieldRef Name='ProjectSubCode' />" +
$"<Value Type='Text'>{item.ProjectSubCode}</Value>" +
$"</Eq>" +
$"</And>" +
$"</Where>" +
$"</Query>" +
$"<RowLimit Paged='TRUE'>30</RowLimit>" +
$"</View>";
var spoItems = spo.GetListItemsBatch(listName, query);
I get the "The attempted operation is prohibited because it exceeds the list view threshold" or "Cannot complete this action. Please try again." issue when i try to run with the above query combination.
It works if i replace the conditions with ID
field and remove and
. Problem is i need it running without providing the ID field in query.