Friday 20 January 2017

CSOM

CSOM:

1. CSOM highly expanded and integrated in sharepoint 2013.

2. Assemblies for the above models are located in the SharePoint file system. 

3. The .Net Client Side Object Model is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI. 

clientContext.ExecuteQuery(); 



Create a console application using Visual Studio


CSOM also needs a starting point in the form of a central object that will instantiate and provide access to the client object model. This central object is called the Client Context. The Client Context object orchestrates requests and initiates actions within a site collection. Once the Client Context Object is initialized, it provides information to the site collection or website through that we can access other SharePoint client objects remotely as depicted in the following code.


Add the references:

 Microsoft.SharePoint.dll and Microsoft.SharePoint.Client.dll.

Example code:
  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://***********/";  
  14.             ClientContext clientContext = new ClientContext(siteUrl);  
  15.             List oList = clientContext.Web.Lists.GetByTitle("TestList");  
  16.             ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();  
  17.             ListItem oListItem = oList.AddItem(listCreationInformation);  
  18.             oListItem["Title"] = "Testing";  
  19.             oListItem.Update();  
  20.             clientContext.ExecuteQuery();  
  21.         }  
  22.     }  
  23. }  

No comments:

Post a Comment