We can use client object model code to retrieve, update, insert and manage data in SharePoint 2016/2013 or SharePoint online.
SharePoint client object model tutorial
SharePoint Online or SharePoint 2016/2013 provides various client object model like below:
- Managed Client Object Model (csom)
- Rest API for SharePoint
- Silverlight client object model
- Windows Phone Assemblies
Microsoft provides various dlls or js file to work with SharePoint. To work with managed client object model we have to use two ddls which can be found in ISAPI (E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\) folder.
To work with the Silverlight client object model, we have to use below two dlls which are found in LAYOUTS\ClientBin folder.
While each of the models provides a different programming interface, each interacts with SharePoint through a Windows Communication Foundation (WCF) service named Client.svc, which is located in the ISAPI directory.
Developers write client-side code using the object model, but the operations are batched and sent as a single Extensible Markup Language (XML) request to the Client.svc service.
Before starting look at the classes below:
Working with Contexts
Server-side object model or client-side object model requires a starting point to work with SharePoint objects. The starting point is known as contexts.
The context object provides an entry point into the associated application programming interface (API) that can be used to gain access to other objects. Once you have access to the objects, you may interact with the scalar properties of the object like Name, Title, Url etc. freely.
The ClientContext class in both the managed and Silverlight object models inherits from the ClientContextRuntime class.
The ClientContextRuntime class provides two methods for loading objects: Load and LoadQuery.
The Load method specifies an object or collection to retrieve, while the LoadQuery method allows you to return collections of objects using a LINQ query.
Executing the Load or LoadQuery method does not cause the client to communicate with the server. Instead, it adds the load operation to a batch that will be executed on the server. In fact, you may execute multiple load methods (as well as other operations) before calling the server.
Each operation is batched, waiting for your code to initiate communication with the server. To execute the batched operations, your code must call the ExecuteQuery or ExecuteQueryAsync method.
The ExecuteQuery method creates an XML request and passes it to the Client.svc service. The client then waits synchronously while the batch is executed and the JSON results are returned.
The ExecuteQueryAsync method, which is used in the Silverlight client object model, sends the XML request to the server, but it returns immediately. Designated success and failure callback methods receive a notification when the batch operation is complete.
You may like following jsom tutorials:
- Display List items in HTML Table using JSOM in SharePoint Hosted App
- Uncaught ReferenceError: web is not defined Error in SharePoint Online JSOM
- Retrieve SharePoint list items programmatically using jsom, rest api and csom
- How to create a list using jsom
- Retrieve all users from all groups using jsom in SharePoint
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com