Hi @nicholas dipiazza ,
No need to get last item Id.
Instead, use CamlQuery.ListItemCollectionPosition to get the paing information like this:
using (var context = new ClientContext("https://tenant.sharepoint.com/sites/dev/"))
{
context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(userName, securePassword);
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
var list = context.Web.Lists.GetByTitle("CamlList");
Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
@"<View Scope='RecursiveAll'>
<RowLimit Page='True' >5000</RowLimit>
</View>";
//Creating a single buffer for storing all the ListItems
List<ListItem> lstListItemCollection = new List<ListItem>();
do
{
ListItemCollection itemCollection = list.GetItems(camlQuery);
context.Load(itemCollection);
try
{
context.ExecuteQuery();
lstListItemCollection.AddRange(itemCollection);
camlQuery.ListItemCollectionPosition = itemCollection.ListItemCollectionPosition;
}
catch (Exception exec)
{
Console.WriteLine(exec.ToString());
}
}
while (camlQuery.ListItemCollectionPosition != null);
}
Reference:
Query ListItems in Batches – SharePoint Online
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.