In this blog, I will to add a code snippet for updating an 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 it name as "Enablefolder".
- Add a Microsoft.Client Assembly reference file in right side Reference tab in Visual Studio.
- Replace Program.cs with the source code below.
Code snippet
- 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");
- ListItem oListItem = oList.Items.GetById(7);
- oListItem["Title"] = "Custom Title updated Programmatically.";
- oListItem.Update();
- clientContext.ExecuteQuery();
-
-
- }
- }
- }
Thanks for reading.