In this blog, I will add a code snippet for deleting 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 a name.
- Add a Microsoft.Client Assembly reference file in the 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.DeleteObject();
- clientContext.ExecuteQuery();
-
-
- }
- }
- }
Thanks for reading.