Create A List Item In SharePoint Using CSOM(Announcement List)
In this blog, I will add a code snippet to add a new item in a SharePoint announcement list, using Client Object model. The Client Object model must conclude with a call to ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler).
Steps
- Open Visual Studio in your system
- Select Console Application template and give the name "Enablefolder"
- Add a Microsoft.Cleint Assembly reference file in right side reference tab in Visual Studio.
- Replace Program.cs with the source code given below.
- using System;
- using Microsoft.SharePoint.Client;
-
-
- namespace GowthamArticles
- {
- class CreateListItem
- {
- static void Main()
- {
-
- ClientContext clientContext = new ClientContext("https://gowtham.sharepoint.com/tutorials");
- List oList = clientContext.Web.Lists.GetByTitle("Announcements");
-
- ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
- ListItem oListItem = oList.AddItem(itemCreateInfo);
- oListItem["Title"] = "Test Item!";
- oListItem["Body"] = "This sample item created programmatically";
-
- oListItem.Update();
-
- clientContext.ExecuteQuery();
- }
- }
- }
Thanks for reading this blog.