Adding items in server object-model
-
02-10-2020 - |
Question
How to add a new item to SharePoint list in server object-model using C#.
This is my code and I want to add items using textboxes
SPWeb web = SPContext.Current.Web;
SPListItemCollection booksListaItems = web.Lists["Books"].GetItems();
foreach(SPListItem item in booksListaItems)
{
lstItems.Items.Add(item.GetFormattedValue("Title"));
}
Solution
Use this:
SPListItem newItem = lstItems.AddItem();
newItem["Title"] = "New Title";
newItem.Update();
Once you get a reference to the item, update the columns, then call the Update method to save your changes.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange