We can use client object model code to retrieve, update, insert and manage data in SharePoint 2016/2013 or SharePoint online. 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 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.
Also read: SharePoint Rest API Tutorials
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 notification when the batch operation is complete.