.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
sivanagamahesh

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

PnP Core Component - Create a custom list in SharePoint 2016

Posted By:Vijai Anand. R       Posted Date: May 16, 2016    Points: 25    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article you will see how to create a custom list in SharePoint 2016 with CSOM Extension Method using Console Application.
 

Please refer Introduction to PnP Core Component for more details. I have created a console application and added SharePointPnPCoreOnline NuGet package for SharePoint 2016 version.

Syntax:

CreateList(Microsoft.SharePoint.Client.Web,Microsoft.SharePoint.Client.ListTemplateType,System.String,System.Boolean,System.Boolean,System.String,System.Boolean)

Description: Adds a custom list to a site.

Parameters:

web: Site to be processed - can be root web or sub site

listType: Built in list template type

listName: Name of the list

enableVersioning: Enable versioning on the list

updateAndExecuteQuery: (Optional) Perform list update and executequery, defaults to true

urlPath: (Optional) URL to use for the list

enableContentTypes: (Optional) Enable content type management

Code Snippet:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;

namespace SP2016PnPCoreComponentDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Input Parameters
            string siteUrl = "http://c7395723754:35298/sites/VijaiDemo";
            string userName = "administrator";
            string password = "xxxxxxxx";
            string domain = "AD2012";
            string listName = "PnP Custom List";

            OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

            try
            {
                // Get the client context
                using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
                {
                    // Create a custom list using CSOM Extension Method
                    ctx.Web.CreateList(ListTemplateType.GenericList, listName, false, true, "", true);
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error Message: " + ex.Message);
            }
        }
    }
}

Output:

A new custom list was created successfully.


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend