Crud Operations on a List

This code block is related to create, delete, update and add list items to a custom list.

[code lang=”c”]

using System;
using Microsoft.SharePoint.Client;
using System.Security;

namespace List_Crud_Operations
class Program
static void Main(string[] args)
ClientContext ctx = new ClientContext(“http://portal/sites/site1”);
Web web = ctx.Web;
var password = “Password”;
SecureString secureString = new SecureString();
foreach (char c in password.ToCharArray()) secureString.AppendChar(c);

ctx.Credentials = new SharePointOnlineCredentials(“”, secureString);
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = “My Custom List”;
creationInfo.Description = “List Creation On SPO”;
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
List mylist = web.Lists.Add(creationInfo);
ctx.ExecuteQuery(); //create a list

mylist = web.Lists.GetByTitle(“Existing Custom List”);
ctx.ExecuteQuery(); // delete an existing list
mylist = web.Lists.GetByTitle(“My Custom List”);
mylist.Description = “update the list”; //Update list

for (int i = 0; i < 10; i++)
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
ListItem item = mylist.AddItem(itemInfo);
item[“Title”] = “Item” + i ;

ctx.ExecuteQuery(); // add items to custom list


This solution is brought to you by our SharePoint professionals.

Softree Consulting employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.

Be it SPFx or SharePoint add-in developments, SharePoint 2019 developments, web part developments, migrating from SharePoint 2010/2013 to SharePoint 2013/2016/Office 365, Office 365, SharePoint hosted apps development or something else in SharePoint, we strive to deliver the best

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *