SharePoint 2013: Delete a List Programmatically using CSOM

Introduction:

In this article we will learn how to delete a list in SharePoint 2013 using .NET Framework client object model (CSOM). We can use the SharePoint client object model to create data in SharePoint 2013.

SharePoint makes the object model available in several forms.

  1. .NET Framework redistributable assemblies-CSOM & SSOM
  2. JavaScript library
  3. REST/OData endpoints

The following article describe tasks that you can complete programmatically, and they include C# code examples that demonstrate CSOM operations.

When you create a Console Application in Visual Studio Select below assembly reference file,

Prerequisites:

  1. Visual Studio 2012
  2. SQL Server
  3. SharePoint Server and Dll
  4. Admin access to the Sharepoint Site.

Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.dll.

Addbelowusing statement to the code file.

usingMicrosoft.SharePoint.Client;

Explanation:

Run Visual Studio and select the Console application and name it Create a List,

console

And select the assembly reference file in Visual studio,

reference file

Then type the below using Statement,

usingMicrosoft.SharePoint.Client;

Source Code:

Then Copy the below csomcode and paste it in Visual Studio,

  1. using System;  
  2. usingSystem.Collections.Generic;  
  3. usingSystem.Linq;  
  4. usingSystem.Text;  
  5. usingSystem.Threading.Tasks;  
  6. usingMicrosoft.SharePoint;  
  7. usingMicrosoft.SharePoint.Client;  
  8.   
  9.   
  10. namespaceDelete_ListItem   
  11. {  
  12.     classProgram  
  13.     {  
  14.         staticvoid Main(string[] args)  
  15.         {  
  16.             ClientContextctx = newClientContext("http://gowtham.sharepoint.com");  
  17.             // The SharePoint web at the URL.  
  18.             Web web = context.Web;  
  19.   
  20.             List list = web.Lists.GetByTitle("TestList");  
  21.             list.DeleteObject();  
  22.   
  23.             context.ExecuteQuery();  
  24.         }  
  25.     }  
  26. }  
OutPut:

output

Check the SharePoint Site Listitem has been deleted successfully.
Ebook Download
View all
Learn
View all