In this article I’m going to discuss how we can create a SharePoint list
programmatically in c# and how we can add columns to the created list.
Actually this is very simple task; this is a sample code.
In
the above code I have created Generic list and normal Text column. You
can use whatever list type and field type according to your requirement
public void createList(){ // choose your site SPSite site = new SPSite("Site URL"); SPWeb web = site.OpenWeb(); SPListCollection lists = web.Lists; // create new Generic list called "My List" lists.Add("My List", "My list Description", SPListTemplateType.GenericList); SPList list = web.Lists["My List"]; // create Text type new column called "My Column" list.Fields.Add("My Column", SPFieldType.Text, true); // make new column visible in default view SPView view = list.DefaultView; view.ViewFields.Add("My Column"); view.Update();}
No comments:
Post a Comment