Following code, runs trough the list and removes each item. Is there any "nicer" way to delete all items from a list? (Except of removing it and recreating it?) Something like List.Purge
var deleteQueryOptions = new List<QueryOption>()
{
new QueryOption("expand", "fields(select=id)")
};
Console.WriteLine("Deleting ROWS from the list (UPDATING)");
var deleteItems = await graphServiceClient.Sites[siteUrl].Lists[listName].Items
.Request(deleteQueryOptions)
.GetAsync();
do
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Processing PAGE of LIST ITEMS");
Console.ResetColor();
foreach (var deleteItem in deleteItems)
{
await graphServiceClient.Sites[siteUrl].Lists[listName].Items[deleteItem.Id]
.Request()
.DeleteAsync();
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Another PAGE of List Items successfully deleted");
Console.ResetColor();
try
{
deleteItems = await deleteItems.NextPageRequest.GetAsync();
}
catch
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("There is no NextPageRequest for deleting items.");
Console.ResetColor();
}
// While there is another page with data, get it and do the process again (At this moment 1 page contains 200 items, written by Marek Kyzivat @ 05/08/2019 )
} while (deleteItems.NextPageRequest != null);
This gets the job done, but once you have a bigger list it can take some time.