How To Create A Custom List In SharePoint 2013 Programmatically

Hello Readers,
 
Welcome to a blog on how to create a custom list in SharePoint 2013 programmatically, using a Console Application. We will use Visual Studio to create a list in SharePoint 2013.
 
Let’s see, how to do it. 
  • Open your Visual Studio.
  • Select New Project.

      
  • Select Console Application.
  • Add the references, which are:
    Microsoft.SharePoint dll and Microsoft.SharePoint.Client dll.
  • Paste the code, given below, under Program.cs.
Code

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Security;  
  5. using System.Net;  
  6. using System.Text;  
  7. using System.Web;  
  8. using System.Data;  
  9. using Microsoft.SharePoint;  
  10. using Microsoft.SharePoint.Client;  
  11. namespace ConsoleApplication1 {  
  12.     class Program {  
  13.         static void Main(string[] args) {  
  14.             //get the web  
  15.             ClientContext context = new ClientContext("http://devtest /SPTests/");  
  16.             Web web = context.Web;  
  17.             //provide the list creation information as Title and Description  
  18.             ListCreationInformation createlist = new ListCreationInformation();  
  19.             createlist.Title = "My List";  
  20.             createlist.Description = "My Custom List";  
  21.             //choose a template as Generic List.  
  22.             createlist.TemplateType = (int) ListTemplateType.GenericList;  
  23.             //add list to SharePoint  
  24.             web.Lists.Add(createlist);  
  25.             context.ExecuteQuery();  
  26.             Console.WriteLine("List Created");  
  27.             Console.ReadKey();  
  28.         }  
  29.     }  
  30. }  

  • Run the code and your custom list will be created.