Insert,Update and Delete Data In SharePoint List on PWA

Insert,Update and Delete Data SharePoint List on PWA :

SharePoint list is use to store data. And SPList data stored in SharePoint content DB. Each row in SPList called sharepoint list item.User can manually store information. But when data store from any third party then we need to write code.Below is complete code for CRUD operation in SPList.


 String PWAURL = SPContext.Current.Web.Url;

            Int itemID = 0;

            using (SPSite Opsite = new SPSite(PWAURL))

                using (SPWeb Opweb = Opsite.OpenWeb())

                    // Fetch the List

                    SPList spList = Opweb.Lists[ListName];

                    SPListItem SPListitem = null;

                    //Add a new item in the List

                    SPListitem = spList.Items.Add();

                    if (itemID > 0)

                        // Update the List item by ID

                        SPListitem = spList.GetItemById(Convert.ToInt32(itemID));


                    SPListitem["ColumnName1"] = Value1;

                    SPListitem["ColumnName2"] = Value2;

                    SPListitem["ColumnName3"] = Value3;

                    SPListitem["ColumnName4"] = Value4;


                    // Delete List item
                    SPListitem = spList.GetItemById(Convert.ToInt32(itemID));


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!