How to Create a new list in SharePoint site using CSOM

Hi All,

In this post we are going see how to create new list in SharePoint site using Client side object model.

Below are the steps to achieve it.

1. Firstly create console application using visual studio 2013.
2. Enter name for solution.
3. Before going to start development make sure you have added two SharePoint  dll (Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Runtime.dll) reference  into reference folder.
4. Use below code to create a new list in SharePoint site.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the context for the SharePoint Site
            ClientContext clientContext = new ClientContext("Enter your SharePoint Site URL");
            // Set Properties for new SharePoint list
            ListCreationInformation listcreationInfo = new ListCreationInformation();
            listcreationInfo.Title = "StudentRecord";
            listcreationInfo.Description = "This list contain all infor about styudent";
            listcreationInfo.TemplateType = (int)ListTemplateType.GenericList;
            //Create a new custom list
            List customlist = clientContext.Web.Lists.Add(listcreationInfo);
            //Now retrieve the custom list properties
            clientContext.Load(customlist);
            // Execute the query to the server
            clientContext.ExecuteQuery();
            //Check result for title property
            Console.WriteLine(customlist.Title);
            Console.ReadLine();
        }
    }

}

पुढे
« Prev Post
Previous
Next Post »