using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.OpenWeb(webUrl)) { SPList list = web.Lists[listName]; SPListItem newItem = list.Items.Add(); newItem["Title"] = "New Item"; newItem["Description"] = "This is a new item"; newItem.Update(); } }
using (SPSite site = new SPSite(siteUrl)) { using (SPWeb web = site.OpenWeb(webUrl)) { SPList list = web.Lists[listName]; SPListItem item = list.GetItemById(itemId); string title = item["Title"].ToString(); string description = item["Description"].ToString(); } }This example retrieves an existing list item from a SharePoint list by calling the GetItemById() method on the list. The item's values are then retrieved using indexer notation and stored in variables. This code would typically be used in a SharePoint workflow or custom event receiver. Package/Library: Microsoft.SharePoint.dll