Raghu's SharePoint Column : SharePoint - My Lifeline!!

Raghu's SharePoint Column

How To Create List Programmatically using Custom List Template (OOB)

How To Create List Programmatically using Custom List Template (OOB)

There are many ways to create a list as follows

1. Creating list Using OOB UI.

2. Creating list Using List Templates

3. Creating list Using Features

4. Creating list programmatically or by a code behind approach

Programmatically a list can be created by writing a console application or by creating exe. The advantage of creating list programmatically will also help you tp retain lookup column in the same list or some other list. I will be discussing regarding lookup column in my next article

This article is written to create a list using out of the box (OOB) custom list template using a code behind approach.The snippet belows shows how to create a list.

using (SPSite site = new SPSite("siteurl”))
SPWeb web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

 Console.WriteLine("Creating Menu List..");

Guid listGuid = web.Lists.Add("ListName”, "Menu Contents For Intranet", SPListTemplateType.GenericList);

Console.WriteLine("List Created...");

The SPListTemplateType has all the OOB cusotm list template such has Announcements, Tasks, Comments etc. The GenericList is a custom list template which I have used in my code


No comments yet.

Leave a Reply

Protected by WP Anti Spam