How To Update List Item In SharePoint Using CSOM

 Update List Item In SharePoint Using CSOM

 Please follow the steps to execute the code in visual studio using Console Application.



Steps:
  1. Open your Visual Studio.
  2. From the template select Console Application and click next.
  3. Enter name and select the location to store the project and click create.
  4. Now your program. cs file will open, write/copy, paste the below-given code.

using Microsoft.SharePoint.Client;
using System;

namespace CSOMCRUD 
 { 
  class Program
   { 
try
     {
        using (ClientContext ctx = new ClientContext("Site URL"))
            {
                Web web = ctx.Web;
// Get List by Title 
                List list = web.Lists.GetByTitle("Employee");
// Enter ID of the Item which you want to Update
                ListItem listItem = list.GetItemById(3);
                listItem["Title"] = "Somshette";
                listItem["Amount"] = 43000;
                listItem["ExpiryDate"] = DateTime.Now;
// Update the List Item
                listItem.Update();
// ExecuteQuery to update the List
                ctx.ExecuteQuery();
            }     
      }
      catch (Exception ex)
        {
           throw;
        }
    }
 }


5. Click F5 or Run the Application.


Thank You for reading. Hope you have enjoyed this! :-)

Comments