doing batch items for add/delete/modify large list on sharepoint online?

Occasional Contributor

Have examples of this in c#?

you can do this in powershell but want it in c#


here it is done in powershell pnp.

2 Replies

Hello, @nellietheelephant, using Microsoft Sharepoint APIs you can easily add, update and delete list items with the help of the program code. Here is a code snippet in C# .Net with all three operations:

using (SPSite oSPsite = new SPSite("http://website url/"))
using (SPWeb oSPWeb = oSPsite.OpenWeb())
            oSPWeb.AllowUnsafeUpdates = true;
            // Fetch the List
            SPList list = oSPWeb.Lists["MyList"];
            //Add a new item in the List
            SPListItem itemToAdd = list.Items.Add();
            itemToAdd["Title"] = "Test Title";
            itemToAdd["Description"] = "Test Description";
            // Get the Item ID
            listItemId = itemToAdd.ID;
            // Update the List item by ID
            SPListItem itemToUpdate = list.GetItemById(listItemId);
            itemToUpdate["Description"] = "Changed Description";
            // Delete List item
            SPListItem itemToDelete = list.GetItemById(listItemId);
            oSPWeb.AllowUnsafeUpdates = false;

If you are an administrator of a Microsoft 365 Enterprise account, this information is critical for keeping your organization's data safe and recoverable. 

@Terry_Lazer  Hi there i know that already but I want it in a way of bulk batches.. cheers