Introduction:
In this article we will learn how to create a List item in SharePoint 2013 using .NET Framework client object model (CSOM).
We can use the SharePoint client object model to create data in SharePoint 2013.
SharePoint makes the object model available in several forms.
- .NET Framework redistributable assemblies-CSOM & SSOM.
- JavaScript library
- REST/OData endpoints
The following article describes tasks that you can complete programmatically, and they include C# code examples that demonstrate CSOM operations.
When you create a Console Application in Visual Studio Select below assembly reference file,
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.dll.
Add below using statement to the code file.
usingMicrosoft.SharePoint.Client;
Run Visual Studio and select the Console application and name it Create a List Then type the below using Statement,
usingMicrosoft.SharePoint.Client;
Create a List item:
And select the assembly reference file in Visual studio,
Source Code:
Then Copy the below csomcode and paste it in Visual Studio,
- using System;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- usingSystem.Threading.Tasks;
- usingMicrosoft.SharePoint;
- usingMicrosoft.SharePoint.Client;
-
-
- namespaceCraete_ListItem
- {
- classProgram
- {
- staticvoid Main(string[] args)
- {
- ClientContextctx = newClientContext("http://gowtham.sharepoint.com");
-
-
- List oList = ctx.Web.Lists.GetByTitle("Announcements");
-
-
- ListItemCreationInformationitemCreateInfo = newListItemCreationInformation();
- ListItemnewItem = oList.AddItem(itemCreateInfo);
- newItem["Title"] = "Test Item!";
- newItem["Body"] = "welcome to Gowtham Blog";
- newItem.Update();
-
- context.ExecuteQuery();
- }
- }
- }
Output: Run F5 and check the sharepoint site.
Check the SharePoint Site. List item has been added successfully.