Advertisement

Responsive Advertisement

Create a new SharePoint list using CSOM

In this article, I have explained how to create and delete SharePoint list, using JavaScript Object Model.

Steps
  1. Open Visual Studio in your system
  2. Select Console Applciation template and give as name "CreateList"
  3. Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
  4. Replace Program.cs with the source code below.

  1. using System.Collections.Generic;  
  2. using System.Linq;  
  3. using System.Text;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.SharePoint.Client;  
  6. namespace CreateList   
  7. {  
  8.     class Program   
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             // ClientContext - Get the context for the SharePoint Site    
  13.   
  14.   
  15.             ClientContext clientContext = new ClientContext("http://gauti.sharepoint.com/sites/SP/");  
  16.             // Specifies the properties of the new custom list    
  17.   
  18.             ListCreationInformation creationInfo = new ListCreationInformation();  
  19.             creationInfo.Title = "NewList";  
  20.             creationInfo.Description = "new list created using VS 2012 &CSOM";  
  21.             creationInfo.TemplateType = (int) ListTemplateType.GenericList;  
  22.             // Create a new custom list    
  23.   
  24.             List newList = clientContext.Web.Lists.Add(creationInfo);  
  25.             // Retrieve the custom list properties    
  26.             clientContext.Load(newList);  
  27.             // Execute the query to the server.    
  28.             clientContext.ExecuteQuery();  
  29.             // Display the custom list Title property    
  30.             Console.WriteLine(newList.Title);  
  31.             Console.ReadLine();  
  32.         }  
  33.     }  
  34. }  

Post a Comment

0 Comments