Adding an Item to the Sharepoint List Programatically

Leave a Comment
The following example will demonstrate , how we will add the Items to the List Programatically

SPSecurity.RunwithElevatedPrivilages(delegate()
{
using(SPSite oSite=new SPSite(SPContext.Current.Site.Url))
{
                       using (SPWeb oWeb = oSite.OpenWeb())
                        {
                            SPList oList = oWeb.Lists.TryGetList("MyListName");
                            if (oList != null)
                            {
                                SPListItem oListItem = oList.GetItems().Add();
                                oListItem["Column1"] = "Column 1 Value";
                                oListItem[""Column1"] = "Column 2 Value";
                                oListItem.Update();
                            }
                        }
}
});

Related Post

0 comments:

Post a Comment