Programmatically adding items to a SharePoint list

using(SPSite site = new SPSite("http://"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["SharePointList"]; // you can use web.GetList method which is better for performance.
SPListItem Item = list.Items.Add();
item["Title"] = txtCompanyName.Text; // the text which need to update
//can add required items
 item.Update();
}
}

Note: 1. No need to use SPSecurity.RunWithElevatedPrivileges.
2. No need to use allowunsafeupdate property
3. No need to update web object.

You may also like below article:-

how to delete items from sharepoint list programmatically
how to update items from sharepoint list programmatically
Get sharepoint list item programmatically

Thanks!
Avinash

calendarMarch 12, 2012 · cardInfoyen · commentsOne Comment
tagTags: , , , ,  · Posted in: List, MOSS, SharePoint

One Response

Leave a Reply

Spam Protection: , required

myworldmaps infoyen