Create List Item in the SharePoint List Using CSOM
Please follow the steps to execute the code in visual studio using Console Application.
Steps:
- Open your Visual Studio.
- From the template select Console Application and click next.
- Enter name and select the location to store the project and click create.
- 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 clientContext = new ClientContext("Site URL"))
{
Web web = clientContext.Web;
// Get List By Title
List myList = web.Lists.GetByTitle("Employee");
// Create Object of ListItemCreationInformation
ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
// Add your ListItem to listItemCreationInformation
ListItem listitem = myList.AddItem(listItemCreationInformation);
// Assign values which you want to Add
listitem["Title"] = "FirstRow";
listitem["Amount"] = 100;
listitem["BirthDate"] = DateTime.Now;
// Update the list
myList.Update();
// Execute the query to save the changes.
clientContext.ExecuteQuery();
}
}
catch (Exception ex)
{
throw;
}
}
}
5. Click F5 or Run the Application.
Thank You for reading. Hope you have enjoyed this! :-)

Comments
Post a Comment