Various ways to add item into a SharePoint 2013 List

SharePoint 2013 add item to list.png
InfoPath alternatives for form designing SharePoint

In this SharePoint 2013 tutorial, we will discuss various ways to add item to a SharePoint 2013 list. We will see how to add item to a SharePoint list using browser, how to add an item to a SharePoint list using SharePoint 2013 server object model?, how to add an item to a sharepoint list programmatically using SharePoint client obejct model and how to add an item to a SharePoint list using web service and jQuery? how to add an item to a list using Rest API? And also we will see how can we add an item to a SharePoint 2013 list using PowerShell?

Read some SharePoint 2013 tutorials below:

Add item to SharePoint List (Out of box):

We can add item to a SharePoint list by using the out of box approach.




Open SharePoint 2013 site containing the list for which you want to add an item.
Select Settings > Site contents, and then in the appropriate list section, select the name of the list.
Select the Items tab, and then in the New group select New Item.
Select Save.

add item to sharepoint list
add item to sharepoint list

Add item in SharePoint list using SharePoint server object model:

Here now we will see how we can add item to SharePoint list using server object model.



//Step to Add new list item programmatically to SharePoint List using C#

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
Using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[“DemoList”];
SPListItem item = list.Items.Add();
item[“Title”] = “using C# :Add new list item programmatically”;
item.Update();
}
}

Add Item Programmatically to SharePoint List using CSOM (Client object model C#):

Here we will discuss how we can add an item to a list programmatically using client object model code (C#.Net).



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

namespace CreateListItem
{
class Program
{
static void Main(string[] args)
{
string siteUrl = “http://servername:2525/”;
ClientContext clientContext = new ClientContext(siteUrl);
List oList = clientContext.Web.Lists.GetByTitle(“DemoList”);
ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(listCreationInformation);
oListItem[“Title”] = “Add item in SharePoint List using CSOM”;
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}

SharePoint : Add item to list using SharePoint Web Services and jQuery:

Now we can see how we can add item to a SharePoint list using SharePoint web service (List.asmx). The jQuery Ajax function is used to POST the data to the Lists.asmx web service.

<script type=”text/javascript”>
//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.
$(document).ready(function() {
$(“#newTaskButton”).click(function() {
CreateNewItem(“Add Item in List with jQuery and the SharePoint Web Services”);
});
});

function CreateNewItem(title)
var batch =
“<Batch OnError=\”Continue\”> \
<Method ID=\”1\” Cmd=\”New\”> \
<Field Name=\”Title\”>” + title + “</Field> \
</Method> \
</Batch>”;
var soapEnv =
“<?xml version=\”1.0\” encoding=\”utf-8\”?> \
<soap:Envelope xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” \
xmlns:xsd=\”http://www.w3.org/2001/XMLSchema\” \
xmlns:soap=\”http://schemas.xmlsoap.org/soap/envelope/\”> \
<soap:Body> \
<UpdateListItems xmlns=\”http://schemas.microsoft.com/sharepoint/soap/\”> \
<listName>DemoList</listName> \
<updates> \
” + batch + “</updates> \
</UpdateListItems> \
</soap:Body> \
</soap:Envelope>”;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl+”/_vti_bin/lists.asmx”,
beforeSend: function(xhr) {
xhr.setRequestHeader(“SOAPAction”,
“http://schemas.microsoft.com/sharepoint/soap/UpdateListItems”);
},
type: “POST”,
dataType: “xml”,
data: soapEnv,
complete: processResult,
contentType: “text/xml; charset=utf-8”
});
}
//The jQuery ajax function call has a complete option which points to a function, in this function you can process the result as follows:
function processResult(xData, status) {
alert(status);
}
</script>

Add item in SharePoint list using Rest API:



Now we will see how we can add item in SharePoint list using Rest API and jQuery. So we need to first reference to latest jquery.min.js

<script type=”text/javascript”>
function _createListItem( listItems, success, failure) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl+ “/_api/web/lists/getbytitle(‘DemoList’)/items”,
type: “POST”,
contentType: “application/json;odata=verbose”,
data: JSON.stringify(listItems),
headers: {
“Accept”: “application/json;odata=verbose”,
“X-RequestDigest”: $(“#__REQUESTDIGEST”).val()
},
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
$(document).ready(function() {
var item = {
“__metadata”: { “type”: itemType },
“Title”: “Add Item in List using REST API”
}
_createListItem(item);
});
</script>

Add new item to SharePoint list using Powershell:

Now we will see how we can add new item to SharePoint list using PowerShell in SharePoint.

#Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
#Variables that we are going to use for list editing
$webURL = “http://yoursiteName”
$listName = “Demo List”
#Get the SPWeb object and save it to a variable
$web = Get-SPWeb $webURL
#Get the SPList object to retrieve the “Demo List”
$list = $web.Lists[$listName]
#Create a new item
$newItem = $list.Items.Add()
#Add properties to this list item
$newItem[“Title”] = “Add item in sharepoint List Using SharePoint PowerShell”
#Update the object so it gets saved to the list
$newItem.Update()

Final Result All the Ways Added Items:

sharepoint 2013 add list item powershell
sharepoint 2013 add list item powershell

Hope this article will be helpful.

Similar SharePoint 2013 Tutorials


About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →

Leave a Reply