Access the Sharepoint List Programmatically
By Devil Scorpio
Here's how to Add New Item into the List or Delete the existing sharepoint List
* * * Add List Items to the Sharepoint List Programmatically * * *
SPSite site = new SPSite("<<Sharepoint Website Name>>");
SPWeb web = site.AllWebs[0];
//"Tasks" is the name of the List
SPList list = web.Lists["Tasks"];
SPListItem newItem = list.Items.Add();
// Add the required data into the list
newItem["Title"] = "Creating New Task";
newItem["Status"] = "Not Started";
newItem["Priority"] = "Normal";
//Save the Item Added to the list
newItem.Update();
* * * Create Sharepoint List Programmatically * * *
SPSite site = new SPSite("<<Sharepoint Website Name>>");
SPWeb web = site.AllWebs[0];
// Create the New List as named "TestTaskList" based on the Task List template
SPListTemplate temps = web.ListTemplates["Tasks"];
Guid newListGuid = web.Lists.Add("TestTaskList", "This List Added Programmatically", temps);
SPList newList = web.Lists[newListGuid];
* * * Delete Sharepoint List Programmatically * * *
SPSite site = new SPSite("<<Sharepoint Website Name>>");
SPWeb web = site.AllWebs[0];
// Select list which we need to delete e.g. "TestTaskList"
SPList list = web.Lists["TestTaskList"];
// Delete the list
list.Delete();
Popularity (1280 Views)
Article Discussion: Access the Sharepoint List Programmatically