Create a list in SharePoint Programatically using C#

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.
  1. public void createList()    
  2. {    
  3.     using (SPSite osite = new SPSite("http://Enter url sharepoint site url"))    
  4.     {    
  5.          osite.AllowUnsafeUpdates = true;    
  6.      
  7.             using (SPWeb oweb= osite.OpenWeb())    
  8.             {    
  9.               oweb.AllowUnsafeUpdates = true;    
  10.      
  11.                // create new Generic list called "My List"    
  12.     
  13.                oweb.Lists.Add("List Name""Description", SPListTemplateType.GenericList);    
  14.     
  15.                // create Text type new column called "My Column"     
  16.     
  17.                SPList list = oweb.Lists["List Name"];    
  18.      
  19.                   
  20.                list.Fields.Add("My Column", SPFieldType.Text, true);    
  21.      
  22.                oSPWeb.AllowUnsafeUpdates = false;    
  23.       }    
  24.      
  25.              oSPsite.AllowUnsafeUpdates = false;    
  26.    }    
  27. }    
Ebook Download
View all
Learn
View all