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
March 12, 2012
В·
Infoyen В·
One Comment
Tags: Add a List Item Programmatically in SharePoint, MOSS, Moss 2007, Programmatically insert an item in sharepoint list, SharePoint В· Posted in: List, MOSS, SharePoint
One Response
Updating a List Item programmatically | SharePoint Solutions - June 21, 2012
Add, Update and Delete List Items Programmatically in Sharepoint
how to delete items from sharepoint list programmatically
how to update items from sharepoint list programmatically
how to add items from sharepoint list programmatically
Leave a Reply