Saturday, October 28, 2017

Different Ways To Add Item In SharePoint 2013 List

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

  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.   
SharePoint REST API: SharePoint REST API and JQuery to Create SharePoint list item.

Reference to latest jquery.min.js.

  1.   
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

Welcome to SharePoint Server 2019, a modern platform for choice and flexibility

“Without continual growth and progress, such words as improvement, achievement, and success have no meaning.” Benjamin Franklin Thi...