How to create a custom task list in SharePoint 2013 using Client Side Object Model

Steps Involved

1.       Open Visual Studio 2012 (Run as administrator).

2.       Go to File=> New => Project.

3.       Select Console Application in the Visual C# node from the installed templates.

4.       Enter the Name and click on Ok.

5.       In the solution explorer, right click on References folder and then click on Add Reference.

6.       Add the following assemblies from 15 hive (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI).

a.       Microsoft.SharePoint.Client.dll

b.      Microsoft.SharePoint.Client.Runtime.dll

7.       Open Program.cs file and replace the code with the following


using System;
using
System.Collections.Generic;

using System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
Microsoft.SharePoint.Client;

namespace CreateTaskList
{
   
/// <summary>
   
/// Console Application
   
/// Create a custom task list using CSOM
   
/// </summary>
   
class Program
    {
       
static void Main(string[] args)
        {
           
// Get the context to the SharePoint site
            ClientContext context =
new ClientContext("http://c4968397007/");

            // The SharePoint web at the URL.
            Web web = context.Web;

            // Create a new object for ListCreationInformation class - used to specify the properties of the new list
            ListCreationInformation creationInfo =
new ListCreationInformation();

            // Specify the tasks list title
            creationInfo.Title =
"Custom Tasks";

            // Specify the tasks list description
            creationInfo.Description =
"My Custom Task List";

            // Specify the list template type
            creationInfo.TemplateType = (
int)ListTemplateType.Tasks;

 
           
// Add the new task list to the list collection
            web.Lists.Add(creationInfo);  
        
           
// Execute the query to the server
            context.ExecuteQuery();
        }
    }

}




Summary:

A custom task list will be created successfully. Thus in this blog we have seen how to create a custom task list in Sharepoint 2013 using Client Side Object Model.


Ebook Download
View all
Learn
View all