How to update a list in SharePoint site using Client side object model

Hi All,

In this post we are going see how to update a list in SharePoint site using Client side object model.

Below code snippet shows basic operations to update a list in SharePoint site.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the context for the SharePoint Site
            ClientContext clientContext = new ClientContext("Enter your SharePoint Site URL");
            // Get the SharePoint list by title
            List olist = clientContext.Web.Lists.GetByTitle("Your Custom list");
            // Get the Sharepoint list Item by id
            ListItem olistItem = olist.GetItemById(1);
            // Update the Stdudent name field
            olistItem["Studentname"] = "Sumit";
            // Update the custom list 
            olistItem.Update();
            //Now retrieve the custom list properties
            clientContext.Load(olist);
            // Execute the query to the server
            clientContext.ExecuteQuery();
            //Check result for title property
            Console.WriteLine("Studen name: "+olist.studentname);
            Console.ReadLine();
        }
    }

}

Happy coding :-)
पुढे
« Prev Post
Previous
Next Post »