Different Ways To Add Item In SharePoint 2013 List

Out-of-box- Add an item to a list:

New item

  1. Navigate to the site containing the list for which you want to add an item.

  2. Select Settings > Site contents and then in the appropriate list section, select the name of the list.

  3. Select the Items tab, and then in the New group select New Item.

  4. Select Save.

Using C#(server object model): Add Item programmatically to SharePoint List using C#.

  1. //Step to Add new list item programmatically to SharePoint List using C#  
  2. using(SPSite site = new SPSite(SPContext.Current.Site.Url))  
  3. {  
  4.     Using(SPWeb web = site.OpenWeb())  
  5.     {  
  6.         SPList list = web.Lists["DemoList"];  
  7.         SPListItem item = list.Items.Add();  
  8.         item["Title"] = "using C# :Add new list item programmatically";  
  9.         item.Update();  
  10.     }  
  11. }  
Using C#(Client object model): Add Item Programmatically to SharePoint List using CSOM.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using Microsoft.SharePoint;  
  6. using Microsoft.SharePoint.Client;  
  7. namespace CreateListItem  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.             string siteUrl = "http://servername:2525/";  
  14.             ClientContext clientContext = new ClientContext(siteUrl);  
  15.             List oList = clientContext.Web.Lists.GetByTitle("DemoList");  
  16.             ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();  
  17.             ListItem oListItem = oList.AddItem(listCreationInformation);  
  18.             oListItem["Title"] = "Add item in SharePoint List using CSOM";  
  19.             oListItem.Update();  
  20.             clientContext.ExecuteQuery();  
  21.         }  
  22.     }  
  23. }  
SharePoint Web Services (jQuery): Add a new item list. The jQuery Ajax function is used to POST the data to the Lists.asmx web service.
  1. <script type="text/javascript">  
  2.   
  3. //The status parameter is a string which can be for example success or error. Finally in the ready event of the document, we'll hook up the click event of the button so the CreateNewItem function is called, with the value of the textbox as the parameter.  
  4.   
  5.         $(document).ready(function() {  
  6.             $("#newTaskButton").click(function() {  
  7.                 CreateNewItem("Add Item in List with jQuery and the SharePoint Web Services");  
  8.         });  
  9.         });   
  10.   
  11.     function CreateNewItem(title) {  
  12.         var batch =  
  13.             "<Batch OnError=\"Continue\"> \  
  14.             <Method ID=\"1\" Cmd=\"New\"> \  
  15.                 <Field Name=\"Title\">" + title + "</Field> \  
  16.             </Method> \  
  17.         </Batch>";  
  18.   
  19.         var soapEnv =  
  20.             "<?xml version=\"1.0\" encoding=\"utf-8\"?> \  
  21.         <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \  
  22.             xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \  
  23.             xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \  
  24.           <soap:Body> \  
  25.             <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \  
  26.               <listName>DemoList</listName> \  
  27.               <updates> \  
  28.                 " + batch + "</updates> \  
  29.             </UpdateListItems> \  
  30.           </soap:Body> \  
  31.         </soap:Envelope>";  
  32.   
  33.         $.ajax({  
  34.             url: _spPageContextInfo.webAbsoluteUrl+"/_vti_bin/lists.asmx",  
  35.             beforeSend: function(xhr) {  
  36.                 xhr.setRequestHeader("SOAPAction",  
  37.                 "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");  
  38.             },  
  39.             type: "POST",  
  40.             dataType: "xml",  
  41.             data: soapEnv,  
  42.             complete: processResult,  
  43.             contentType: "text/xml; charset=utf-8"  
  44.         });  
  45.     }  
  46.   
  47.     //The jQuery ajax function call has a complete option which points to a function, in this function you can process the result as follows:  
  48.   
  49.     function processResult(xData, status) {  
  50.         alert(status);  
  51.     }  
  52.   
  53. </script>  
SharePoint REST API: SharePoint REST API and JQuery to Create SharePoint list item.

Reference to latest jquery.min.js.
  1. <script type="text/javascript">  
  2.   
  3.     function _createListItem( listItems, success, failure) {  
  4.          
  5.           
  6.         $.ajax({  
  7.             url: _spPageContextInfo.webAbsoluteUrl+ "/_api/web/lists/getbytitle('DemoList')/items",  
  8.             type: "POST",  
  9.             contentType: "application/json;odata=verbose",  
  10.             data: JSON.stringify(listItems),  
  11.             headers: {  
  12.                 "Accept""application/json;odata=verbose",  
  13.                 "X-RequestDigest": $("#__REQUESTDIGEST").val()  
  14.             },  
  15.             success: function (data) {  
  16.                 success(data);  
  17.             },  
  18.             error: function (data) {  
  19.                 failure(data);  
  20.             }  
  21.         });  
  22.     }  
  23.   
  24.   
  25.           
  26.         $(document).ready(function() {  
  27.             var item = {  
  28.                 "__metadata": { "type": itemType },  
  29.                 "Title""Add Item in List using REST API"  
  30.             }  
  31.             _createListItem(item);  
  32.           
  33.         });   
  34.   
  35.   
  36. </script>  
SharePoint PowerShell: Adding list items using PowerShell SharePoint.
  1. #Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets  
  2. Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue  
  3.  
  4. #Variables that we are going to use for list editing  
  5. $webURL = "http://yoursiteName"  
  6. $listName = "Demo List"  
  7.  
  8. #Get the SPWeb object and save it to a variable  
  9. $web = Get-SPWeb $webURL  
  10.  
  11. #Get the SPList object to retrieve the "Demo List"  
  12. $list = $web.Lists[$listName]  
  13. #Create a new item  
  14. $newItem = $list.Items.Add()  
  15.  
  16. #Add properties to this list item  
  17. $newItem["Title"] = "Add item in sharepoint List Using SharePoint PowerShell"  
  18.  
  19. #Update the object so it gets saved to the list  
  20. $newItem.Update()  
Final result shows all the Added Items:

Demolist

 

Up Next
    Ebook Download
    View all
    Learn
    View all