Create a list in SharePoint Programatically using C#
In this blog I'm going to discuss how we can create a SharePoint list pro grammatically in c# and how we can add columns to the created list.
Actually this is very simple task; this is a sample code.call the below function in your code or try with a console application in vs 2010/2012.
- public void createList()
- {
- using (SPSite osite = new SPSite("http://Enter url sharepoint site url"))
- {
- osite.AllowUnsafeUpdates = true;
-
- using (SPWeb oweb= osite.OpenWeb())
- {
- oweb.AllowUnsafeUpdates = true;
-
-
-
- oweb.Lists.Add("List Name", "Description", SPListTemplateType.GenericList);
-
-
-
- SPList list = oweb.Lists["List Name"];
-
-
- list.Fields.Add("My Column", SPFieldType.Text, true);
-
- oSPWeb.AllowUnsafeUpdates = false;
- }
-
- oSPsite.AllowUnsafeUpdates = false;
- }
- }