Jul 09 2022 10:45 AM - edited Jul 21 2022 08:55 AM
Have examples of this in c#?
you can do this in powershell but want it in c#
here it is done in powershell pnp.
https://pnp.github.io/script-samples/spo-list-items-large-lists/README.html?tabs=pnpps
Jul 21 2022 08:19 AM
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";
itemToAdd.Update();
// Get the Item ID
listItemId = itemToAdd.ID;
// Update the List item by ID
SPListItem itemToUpdate = list.GetItemById(listItemId);
itemToUpdate["Description"] = "Changed Description";
itemToUpdate.Update();
// Delete List item
SPListItem itemToDelete = list.GetItemById(listItemId);
itemToDelete.Delete();
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.
Jul 21 2022 08:50 AM
@Terry_Lazer Hi there i know that already but I want it in a way of bulk batches.. cheers