Create list using object model in SharePoint


In this post we will discuss about how to create a custom list using SharePoint object model. Also you can check my previous posts on:

– Content Editor Web Part in SharePoint 2010

– Get all users from web application in SharePoint using PowerShell

– Check if list exists or not using TryGetList method in SharePoint 2010

You can create SharePoint list by using SharePoint server object model. Here is the code to create an employee list using the Contacts list template type.

SPWeb site = SPContext.Current.Web;

string ListTitle = “Employees”; // Title of the list

string ListDescription = “EnjoySharePoint Employees List”; //Description of the list.

Guid ListId = site.Lists.Add(ListTitle, ListDescription, SPListTemplateType.Contacts);

SPList list = site.Lists[ListId];

list.OnQuickLaunch = true; //This is to show the list in the quicklaunch.


list.Update();

The above code will create Employees list.


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply