Navigation

Saturday, 10 January 2015

Add record in SharePoint List


Below is the code block to add item in SharePoint List

using (SPSite oSPsite = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
      {
            oSPWeb.AllowUnsafeUpdates = true;
            // Fetch the List
            SPList list = oSPWeb.Lists["ListName"];
                   
            //Add a new item in the List
            SPListItem item = list.Items.Add();
            item["Title"] = "Test Title1";
            item.Update();
            oSPWeb.AllowUnsafeUpdates = false;
       }

}

No comments:

Post a Comment