Client Side Object Model (CSOM)?

Client Side Object Model (CSOM)?

Client Side Object Model (CSOM)?. Client-side object model(CSOM) is used to access SharePoint remotely, means using the .net managed code developer easily can access SharePoint functionality. It was introduced in SharePoint 2010. Client.svc one of the web service is the heart of Client side object model(CSOM), which lives in the _vti_bin virtual directory.SharePoint Client-Side Object Model (CSOM) to use develop task like Update, Insert, Retrieve data in SharePoint Project server 2013(Online and On-premise).

There are two assemblies for .net managed code to access SharePoint remotely using CSOM
Below are steps to add this assembly to your simple console application with .net managed code.

1. Open visual studio and create a simple console application.
2. Add two SharePoint dlls as given
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll

Below is code to access SharePoint using Client side object model


If you are using CSOM inside SharePoint farm, means inside SharePoint Web Part etc then you don’t need to pass User Id and Password to authenticate the user because the code is running in user context like this.

using (var ctx = new ClientContext("your site url")) {
            var web = context.Web;
            string title=web.Title;
            int count=web.Lists.Count;

If you want to access SharePoint remotely then you need to pass your service account user id and password like this.

for SharePoint on-premises

        static string UserName = "User Name";
        static string Passwords = "Password";
        public static string SiteURL = "SiteURL";

using (ClientContext clientCont = new ClientContext(SiteURL))//PWA Url
                SecureString passWord2 = new SecureString();
                foreach (char c in Passwords.ToCharArray()) passWord2.AppendChar(c);
                clientCont.Credentials = new NetworkCredential(UserName, passWord2);
                var web = context.Web;
            	string title=web.Title;
            	int count=web.Lists.Count;

for SharePoint Online change this line only

clientCont.Credentials = new SharePointOnlineCredentials(UserName, passWord2);



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!