Create, Update, Delete a List Item in SharePoint 2013 by Client Object Model

Create List Item:

Add the references Microsoft.SharePoint.dll and Microsoft.SharePoint.Client.dll.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
namespace CreateListItem
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = "http://servername:7777/";
            ClientContext clientContext = new ClientContext(siteUrl);
            List oList = clientContext.Web.Lists.GetByTitle("ListTitle");
            ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
            ListItem oListItem = oList.AddItem(listCreationInformation);
            oListItem["Title"] = "Hello World";
            oListItem.Update();
            clientContext.ExecuteQuery();
        }
    }
}

Update List Item:

Add the references Microsoft.SharePoint.dll and Microsoft.SharePoint.Client.dll.

using System;
using System.Collections.Generic; 
using System.Linq;
using System.Text; 
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

namespace UpdateListItem
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = "http://servername:7777/";
            ClientContext clientContext = new ClientContext(siteUrl);
            List oList = clientContext.Web.Lists.GetByTitle("ListTitle");
            ListItem oListItem = oList.GetItemById(1);
            oListItem["Title"] = "Hello World Updated.";
            oListItem.Update();
            clientContext.ExecuteQuery();
        }
    }
}

Delete List Item:

Add the references Microsoft.SharePoint.dll and Microsoft.SharePoint.Client.dll.
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.Client;

namespace UpdateListItem
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = "http://servername:7777/";
            ClientContext clientContext = new ClientContext(siteUrl);
            List oList = clientContext.Web.Lists.GetByTitle("ListTitle");
            ListItem oListItem = oList.GetItemById(1);         
            oListItem.DeleteObject();
            clientContext.ExecuteQuery();
        }
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s