SharePoint 2013 Basic Operations Using CSOM - Create List

Introduction

SharePoint 2013 is a Browser-based collaboration, document management platform and is widely used in many organizations.SharePoint is like a document repository i.e. secure place to store, organize, share and access information from almost any device.

SharePoint 2013 can store all the types of documents, pages, links etc.

In SharePoint 2013, we do not need any separate software to install on a customer place. It's like a Browser based platform and we can use it in anyplace and anywhere.

Now, SharePoint has two main platforms and it can be quickly explained below.

  • SharePoint Online
  • SharePoint Server

SharePoint Online is a Cloud-based Service, hosted by Microsoft and we can use it in O365 .

SharePoint Server is a platform to be maintained by us and we have to maintain all deployment and maintenance support.

Microsoft says, SharePoint 2013 as Collaboration, Portal, Search, Enterprise Content Management (ECM), Business Process Management (BPM) and Business Intelligence (BI) etc.

Here, my tutorial is to explain about how we can use SharePoint 2013 in a program and SharePoint 2013 OOTB works well.

In this blog, I would perform basic operations with SharePoint 2013 .NET Framework Client Object Model (CSOM).

SharePoint 2013 supports API methods given below to perform basic operations like create, update, read and delete .

  1. Server Side Object Model (SSOM)
  2. Client Object Model (CSOM)
  3. JavaScript Object Model (JSOM)
  4. REST

Server Side Object Model is pure .NET code but here, one needs to use Client Object Model to perform all the basic operations in SharePoint 2013 to achieve all this.

Prerequisites to perform this operations.

  • Visual studio 2012
  • SharePoint 2013

Before start to develop the code we have to add dll assembly reference .

  1. SharePoint.Client.Runtime.dll
  2. SharePoint.Client.dll

Add the line given below in your namespace,

  1. using Microsoft.SharePoint.Client;  

Now, we are going to see how to create a list in SharePoint 2013 programmatically.

In Client Object Model, we will use the class given below to interact with the objects within your site, such as the current Web object, the parent site object and a list collection, once we use this ExecuteQuery method on the ClientContext instance.

Open your Visual Studio 2012 in your system and click New Project link.


Once opened, your Visual Studio will add DLL reference here.


Subsequently, copy and paste your code here.


Click F5 to run this solution and open your SharePoint site.


Source Code 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text.RegularExpressions;  
  5. using Microsoft.SharePoint.Client;  
  6. namespace Rextester {  
  7.     public class Program {  
  8.         public static void Main(string[] args) {  
  9.             ClientContext context = new ClientContext("http://gowtham.sharepoint.com");  
  10.             Web web = context.Web;  
  11.             ListCreationInformation creationInfo = new ListCreationInformation();  
  12.             creationInfo.Title = "Tutorial";  
  13.             creationInfo.TemplateType = (int) ListTemplateType.GenericList;  
  14.             List list = web.Lists.Add(creationInfo);  
  15.             list.Description = "Programmatically Created List";  
  16.             list.Update();  
  17.             context.ExecuteQuery();  
  18.         }  
  19.     }  
  20. }   

Thanks for reading my blogs.

Ebook Download
View all
Learn
View all