25+ SharePoint .Net Client Object Model Examples

SharePoint .Net Client Object Model Examples

In this SharePoint tutorial, we will discuss SharePoint client object model, what are various SharePoint client object model techniques available. How can we work with client object model in SharePoint Online/2013/2016? We will also see more than 25+ examples in the SharePoint client object model.

Here, we will focus purely in SharePoint .Net client object model. The same .Net managed object model code will work in almost same in SharePoint 2010/2013/2016 and SharePoint Online.

SharePoint deveopment training course

SharePoint 2016 Tutorial Contents

What is SharePoint client object model?

SharePoint client object model (CSOM) provides lots of APIs to retrieve, update, and manage data in SharePoint. There are limitations to what can be done client side compared to server side, say for example:

  • You cannot access the FARM level properties, you can get/set only the properties at the web application level.
  • We cannot elevate the privilege in COM as we can do in server object model.
  • No SharePoint installation is required in the development machine.Only the Client DLL’s are required.
  • No Compilation required as required on the server side, NO IISRESET required.

Different types of SharePoint client object model

There are 4 types of SharePoint client object model available to work with SharePoint 2013/2016/2010 or SharePoint Online.

  • .Net client object model (C#.Net)
  • JavaScript client object model (jsom)
  • Rest API
  • Silverlight client object model
  • Windows Phone client object model

.Net client object model (C#.Net):

The Managed object model can be used to create .NET applications that run on Windows operating systems that aren’t phones or SharePoint servers. The managed client object model dlls are found inside the ISAPI folder ( %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\ISAPI).

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

JavaScript client object model:

JavaScript client object model does not contain any dlls, rather it contains .js files. These .js files are located inside the LAYOUTS folder and mainly functionality exists inside SP.js and SP.Core.js. The JavaScript object model can be used in an inline script or in separate .js files. You may like:

Rest API:

In SharePoint 2013 now you can interact remotely with SharePoint sites using REST API. You will be able to interact by using any technology that supports REST web requests. You need to construct a RESTful HTTP request, using the Open Data Protocol (OData) standard. You may like SharePoint Rest API examples:

Silverlight client object model

By using Silverlight object model, you can build Silverlight applications, Web Parts, Asp.Net applications, apps for SharePoint and Office, and Silverlight applications for phones that use SharePoint data or SharePoint objects.

The Silverlight client object model dlls are presented inside %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\TEMPLATE\LAYOUTS\ClientBin folder.

  • Microsoft.SharePoint.Client.Silverlight.dll
  • Microsoft.SharePoint.Client.Silverlight.Runtime.dll

Windows Phone client object model

The Mobile object model can be used to create applications that run on Windows Phones. The Mobile client-side object model contains some functionality that is specific to phones, such as APIs that enable a phone app to register for notifications from the Microsoft Push Notification Service.

The required dlls are found inside %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\TEMPLATE\LAYOUTS\ClientBin folder. The dlls are:

  • Microsoft.SharePoint.Client.Phone.dll
  • Microsoft.SharePoint.Client.Phone.Runtime.dll

Here we will see examples in .Net client object model (C#.Net). Now we will see 15+ SharePoint .Net Client Object Model Examples.

We can use these .Net client object model code in a Console application, windows application or in a web application like asp.net web application or mvc application.

If you do not have SharePoint installed and you are trying to connect to the SharePoint Online site, you can download the required dlls from NuGet. I wrote an article on SharePoint client object model.

15+ SharePoint .Net Client Object Model Examples

Here are few examples of SharePoint .Net client object model examples.

Retrieve SharePoint site title and description in SharePoint client object model

Here we will see how we can retrieve SharePoint site title and description using SharePoint .Net client object model in SharePoint 2013/2016/2010.

void GetWebTitle()
{
ClientContext context = new ClientContext(“http://[Site URL]”);
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
string webTitle = web.Title;
string webDescription = web.Description;
}

Create SharePoint list programmatically using .Net Client object model (CSOM)

Now, we will discuss how we can create a SharePoint list programmatically using .Net client object model (CSOM) in SharePoint 2010/2013/2016.The below code will create an announcement list in SharePoint using csom.

using (ClientContext context = new ClientContext(“http://bsahoo3:8787/sites/Training”))
{
//Create a new list
ListCreationInformation listCreationInformation = new ListCreationInformation();
listCreationInformation.Title = “My Announcements List”;
listCreationInformation.Description += “Here is my list created by client object midel”;
listCreationInformation.TemplateType = (int)ListTemplateType.Announcements;
listCreationInformation.QuickLaunchOption = Microsoft.SharePoint.Client.QuickLaunchOptions.On;
List list = context.Web.Lists.Add(listCreationInformation);
context.ExecuteQuery();
}

Create a Custom list and add an item to custom list programmatically using the SharePoint client object model

We can create list and add item to a SharePoint 2013 list using managed client object model.

string webUrl =”http://WebURL”;
using (ClientContext ctx = new ClientContext(webUrl))
{
//Below is the code to create a list
ListCreationInformation listInfo = new ListCreationInformation();
listInfo.Title = “My Test List”;
listInfo.Description += “This is a test description for a test list.”;
listInfo.TemplateType = (int)ListTemplateType.GenericList;
listInfo.QuickLaunchOption = Microsoft.SharePoint.Client.QuickLaunchOptions.On;
List list = ctx.Web.Lists.Add(listInfo);
ctx.ExecuteQuery();

//Below is the code to add an item to the list:

ListItemCreationInformation newlistitem = new ListItemCreationInformation();
ListItem item = list.AddItem(newlistitem);
item[“Title”] = “New Test Item”;
item.Update();
ctx.ExecuteQuery();
}

Update SharePoint list programmatically using CSOM

Now, we will see how we can update list title and description using SharePoint .Net managed client object model (CSOM).

ClientContext context = new ClientContext(“http://WebSiteUrl”);
Web web = context.Web;
List myList = web.Lists.GetByTitle(“My New List”);
myList.Title = “My New List Modified”;
myList.Description=”This is modified list description!”;
list.Update();
context.ExecuteQuery();

Delete SharePoint list programmatically using CSOM

Below is the SharePoint client object model code to delete SharePoint list programmatically using CSOM.

ClientContext context = new ClientContext(“http://WebSiteUrl”);
Web web = context.Web;
List list = web.Lists.GetByTitle(“My New List”);
list.DeleteObject();
context.ExecuteQuery();

Get SharePoint List Title using .Net Client object model (CSOM)

Now, we will see how to retrieve list title using .Net client object model (csom) in SharePoint 2010/2013/2016.

ClientContext context = new ClientContext(“http://bsahoo3:2500/sites/MyTest/”);
List list = context.Web.Lists.GetByTitle(“MyCustomList”);
context.Load(list);
context.ExecuteQuery();
Label1.Text = list.Title;

Retrieve SharePoint list items and display in Gridview using SharePoint Client object model (csom)

Now we will see how we can retrieve list items and display in a gridview using SharePoint .Net client object model in SharePoint 2010/2013/2016.

ClientContext context = new ClientContext(“http://bsahoo3:2500/sites/MyTest/”);
List list = context.Web.Lists.GetByTitle(“MyCustomList”);
CamlQuery query = new CamlQuery();
query.ViewXml = “<View/>”;
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);
context.Load(list);
context.Load(items);
context.ExecuteQuery();
DataTable table = new DataTable();
table.Columns.Add(“Id”);
table.Columns.Add(“Title”);
foreach (Microsoft.SharePoint.Client.ListItem item in items)
table.Rows.Add(item.Id, item[“Title”]);
GridView1.DataSource = table;
GridView1.DataBind();

The above code will read all list items and will show the list data in a gridview.

Update SharePoint list items using client object model (CSOM)

Now, we will see how we can modify all list items using SharePoint .Net client object model code in SharePoint.

ClientContext context = new ClientContext(“http://bsahoo3:2500/sites/MyTest/”);
List list = context.Web.Lists.GetByTitle(“MyCustomList”);
CamlQuery query = new CamlQuery();
query.ViewXml = “<View/>”;
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);

context.Load(list);
context.Load(items);
context.ExecuteQuery();

foreach (Microsoft.SharePoint.Client.ListItem item in items)
{
item[“Title”] = item[“Title”] + ” Modified”;
item.Update();
}
context.ExecuteQuery();

The above code will update each SharePoint list item and will add Modified with the existing title.

Insert item to SharePoint List using SharePoint Client object model

We can easily insert item to SharePoint list using .Net client object model in SharePoint 2013/2016/2010.

Here I have a custom list having 3 columns as: Title, Description & TaskStatus.

ClientContext context = new ClientContext(“http://bsahoo3:2500/sites/MyTest/”);
List list = context.Web.Lists.GetByTitle(“MyCustomList”);

ListItemCreationInformation newItem = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem listItem = list.AddItem(newItem);
listItem[“Title”] = “New Item Added”;
listItem[“Description”] = “New Item Description”;
listItem[“TaskStatus”] = “False”;
listItem.Update();
context.ExecuteQuery();

Delete SharePoint List item programmatically using SharePoint Client object model (C#)

Now, we will discuss how we can delete a list item programmatically using SharePoint client object model. The below CSOM code will delete an item whose title is “New Task”.

ClientContext context = new ClientContext(“http://bsahoo3:2500/sites/MyTest/”);
List list = context.Web.Lists.GetByTitle(“MyCustomList”);
CamlQuery query = new CamlQuery();
query.ViewXml = “<View/>”;
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);

context.Load(list);
context.Load(items);
context.ExecuteQuery();

foreach (Microsoft.SharePoint.Client.ListItem item in items)
{
if (item[“Title”].ToString() == "New Task")
item.DeleteObject();
break;
}

Check if list exists in SharePoint online using .Net managed object model CSOM

In this example we will discuss how we can check if list exists in SharePoint online using .Net managed object model code (CSOM).

In .Net client object model there is not direct method which will return whether the list is presented or not. If the list does not exits then when we run the context.ExecuteQuery(); it will go to the exception block and it will return message like below:

List ‘MyListName’ does not exist at site with URL ‘https://onlysharepoint2013.sharepoint.com/sites/Bhawana’.

So from the exception we have to catch that the list is not exists. Full code is like below:

private void btnClick_Click(object sender, EventArgs e)
{
bool isListExists = IsListExist();
}

private bool IsListExist()
{
bool isExists = false;
using (ClientContext context = new ClientContext(“https://onlysharepoint2013.sharepoint.com/sites/Bhawana/”))
{
string username = "********@onlysharepoint2013.onmicrosoft.com";
context.AuthenticationMode = ClientAuthenticationMode.Default;
var secureString = new SecureString();
foreach (char c in “********”)
{
secureString.AppendChar(c);
}
context.AuthenticationMode = ClientAuthenticationMode.Default;
context.Credentials = new SharePointOnlineCredentials(username, secureString);
try
{
List lst = context.Web.Lists.GetByTitle("MyListName");
context.Load(lst);
context.ExecuteQuery();
if (lst != null)
{
if (lst.ItemCount >= 0)
{
isExists = true;
}
}
}

catch (Exception ex)
{
isExists = false;
}
}
return isExists;
}

Get column names of SharePoint list using SharePoint client object model (CSOM)

Learn how to get column names of a SharePoint list using the SharePoint client object model. The code will work in SharePoint 2010/2013/2016.

ClientContext context = new ClientContext(“http://URL of the Site”);
Web web = context.Web;
List list = site.Lists.GetByTitle(“ListName”);
context.Load(list);
context.ExecuteQuery();
FieldCollection fieldCollection = list.Fields;
context.Load(fieldCollection);
context.ExecuteQuery();
foreach (Field field in fieldCollection)
{
Console.WriteLine(“Name: ” + field.InternalName.ToString());
}
Console.ReadLine();

The above csom code will display all columns from SharePoint list.

Update web part Title using SharePoint Client object model

Below is SharePoint CSOM code to update web part title using SharePoint client object model.

ClientContext ctx = new ClientContext(“http://URL of the site”);
Web oWeb = ctx.Web;
File file = oWeb.GetFileByServerRelativeUrl(“/default.aspx”);
LimitedWebPartManager limitedWebPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
ctx.Load(limitedWebPartManager.WebParts,wps => wps.Include(wp => wp.WebPart.Title));
ctx.ExecuteQuery();
if (limitedWebPartManager.WebParts.Count > 0)
WebPartDefinition oWebPartDef = limitedWebPartManager.WebParts[0];
oWebPartDef.WebPart.Title = “New webpar Title”;
oWebPartDef.SaveWebPartChanges();
ctx.ExecuteQuery();
}

Delete a SharePoint online list using CSOM C#.Net managed object model code

We will see how we can delete a SharePoint online list using csom c#.net managed object model in SharePoint online. We are going to do this inside a console application. Here we are retrieving the SharePoint list using the GetByTitle method. And we are deleting the list by calling the DeleteObject() method.

public void DeleteTemporaryList(string URL)
{
using (ClientContext clientContext = new ClientContext(URL))
{
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
clientContext.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
List tempList;
try
{
tempList = clientContext.Web.Lists.GetByTitle(“MyTempList”);
clientContext.Load(tempList);
clientContext.ExecuteQuery();
tempList.DeleteObject();
clientContext.ExecuteQuery();
}

catch (Exception ex)
{
}
}
}

private static string GetSPOAccountName()
{
try
{
return ConfigurationManager.AppSettings[“SPOAccount”];
}
catch
{
throw;
}
}
private static SecureString GetSPOSecureStringPassword()
{
try
{
var secureString = new SecureString();
foreach (char c in ConfigurationManager.AppSettings[“SPOPassword”])
{
secureString.AppendChar(c);
}
return secureString;
}
catch
{
throw;
}
}

Check if current site is root site using .net managed object model code csom in SharePoint online

Now we will discuss how we can check if the current site is a root site using .Net managed client object model code in SharePoint online. Here I have a site URL and I want to check if the site is a root site using csom (.net managed object model code).

Below is the full code to get the result. Here we are retrieving the credentials by using GetSPOAccountName(),

GetSPOSecureStringPassword() to connect to SharePoint online site which has been explained in the console application.

public static string CheckRootweb()
{
var isRootWeb = false;

using (ClientContext context = new ClientContext(“https://onlysharepoint2013.sharepoint.com/sites/Bhawana/subsite1”))
{
context.AuthenticationMode = ClientAuthenticationMode.Default;
context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
context.Load(context.Site.RootWeb, rw => rw.Id);
context.Load(context.Web, w => w.Id);
context.ExecuteQuery();
isRootWeb = (context.Site.RootWeb.Id == context.Web.Id) ? true : false;
}

return isRootWeb.ToString();

If you will run the code, you can see the isRootWeb value like below:

SharePoint .Net Client Object Model Examples
SharePoint .Net Client Object Model Examples

Create Custom List and add columns and insert data using SharePoint Client Object Model

Now we will discuss how to create a custom list, add columns into the list using SharePoint client object model.

Then we will discuss how to add few items into the SharePoint list using SharePoint 2010/2013/2016 client object model.

Below is the full code to create a custom list using client object model:

using System;
using Microsoft.SharePoint.Client;
class Program
{
static void Main()
{
ClientContext clientContext =new ClientContext(“http://intranet.contoso.com”);
Web site = clientContext.Web;
// Create a list.

ListCreationInformation listCreationInfo =new ListCreationInformation();
listCreationInfo.Title = “Client API Test List”;
listCreationInfo.TemplateType = (int)ListTemplateType.GenericList;
List list = site.Lists.Add(listCreationInfo);

// Add fields to the list.
Field field1 = list.Fields.AddFieldAsXml(
@”<Field Type=’Choice’
DisplayName=’Category’
Format=’Dropdown’>
<Default>Specification</Default>
<CHOICES>
<CHOICE>Specification</CHOICE>
<CHOICE>Development</CHOICE>
<CHOICE>Test</CHOICE>
<CHOICE>Documentation</CHOICE>
</CHOICES>
</Field>”,true, AddFieldOptions.DefaultValue);

Field field2 = list.Fields.AddFieldAsXml(
@”<Field Type=’Number’ DisplayName=’Estimate’/>”,true, AddFieldOptions.DefaultValue);

// Add some data.

ListItemCreationInformation itemCreateInfo =new ListItemCreationInformation();
ListItem listItem = list.AddItem(itemCreateInfo);
listItem[“Title”] = “Write specs for user interface.”;
listItem[“Category”] = “Specification”;
listItem[“Estimate”] = “20”;
listItem.Update();
listItem = list.AddItem(itemCreateInfo);
listItem[“Title”] = “Develop proof-of-concept.”;
listItem[“Category”] = “Development”;
listItem[“Estimate”] = “42”;
listItem.Update();
listItem = list.AddItem(itemCreateInfo);
listItem[“Title”] = “Write test plan for user interface.”;
listItem[“Category”] = “Test”;
listItem[“Estimate”] = “16”;
listItem.Update();
listItem = list.AddItem(itemCreateInfo);
listItem[“Title”] = “Validate SharePoint interaction.”;
listItem[“Category”] = “Test”;
listItem[“Estimate”] = “18”;
listItem.Update();
listItem = list.AddItem(itemCreateInfo);
listItem[“Title”] = “Develop user interface.”;
listItem[“Category”] = “Development”;
listItem[“Estimate”] = “18”;
listItem.Update();
clientContext.ExecuteQuery();
}
}

Follow or UnFollow people by using SharePoint client object model

Now in this SharePoint client object model tutorial, we will discuss how we can follow or unfollow people by using the SharePoint 2013 client object model. Programmatically we can follow or unfollow people in SharePoint 2013/2016.

Remember the logged in user should have Full Control permission to the user profile service application. Here we will use SocialFollowingManager class.

ClientContext clientContext = new ClientContext(“http://ServerURL”);
SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);
SocialActorInfo actorInfo = new SocialActorInfo();
actorInfo.AccountName = “domain\\username”;
ClientResult<bool> isFollowed = followingManager.IsFollowed(actorInfo);
clientContext.ExecuteQuery();
if (isFollowed == true)
{
//If the user already following you can stop following by calling the StopFollowing() method.
followingManager.StopFollowing(actorInfo);
clientContext.ExecuteQuery();
}
else
{
//If the user is not follwing then you can follow by using the Follow() method.
followingManager.Follow(actorInfo);
clientContext.ExecuteQuery();
}

Query Search with SharePoint 2013/2016 Client Object Model

Now, will discuss how to query search with SharePoint 2013 client object model.

To work with SharePoint 2013 Search Client Object Model, we need to add below assemblies which are located inside ISAPI folder of the 15 hive directory.

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll
  • Microsoft.SharePoint.Client.Search.dll

Then in the code write the corresponding using statements:

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Search;
using Microsoft.SharePoint.Client.Search.Query;

using (ClientContext clientContext = new ClientContext(“http://ServerName”))
{
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
keywordQuery.QueryText = “SharePoint 2013”;
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();
}

After that you can iterate through the ResultTableCollection like below:

foreach (var resultRow in results.Value[0].ResultRows)
{
string Title = resultRow[“Title”];
string Path = resultRow[“Path”];
}

Get followers by using SharePoint 2013 .Net client object model

In this SharePoint csom example, we will discuss how we can get followers as well as followed by people by using.Net client object model in SharePoint 2013/2016.

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Social;
ClientContext clientContext = new ClientContext(“http://URL”);
SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);
SocialActorInfo actorInfo = new SocialActorInfo();
actorInfo.AccountName = “domain\\username”;
//By using the GetFollowed method you can get the people who the current user is following.
ClientResult<SocialActor[]> followedResult = followingManager.GetFollowed(SocialActorTypes.Users);
//By using the GetFollowers() method you can get the people who are following the current user.
ClientResult<SocialActor[]> followersResult = followingManager.GetFollowers();
clientContext.ExecuteQuery();
Once you get the resultset you can iterate like below:
foreach (SocialActor actor in followedResult)
{
string name = actor.Name;
string imageURL = actor.ImageUri;
}

Get SharePoint column display name and internal name using SharePoint client object model

This SharePoint client object model example explains, how to get display and internal name for columns or fields in SharePoint using SharePoint client object model

Below is the SharePoint client object model code to get SharePoint column display name and internal name using the SharePoint client object model.

string url = "http://SiteURL";
ClientContext context = new ClientContext(url);
Web web = context.Web;
var list = web.Lists.GetByTitle("Announcements");
context.Load(list.Fields);
context.ExecuteQuery();
string title = string.Empty;
string internalName = = string.Empty;
foreach (Field f in list.Fields)
{
title += field.Title + " ";
internalName += field.InternalName + " ";
}

Retrieve selected properties of website using SharePoint 2013 client object model

This SharePoint client object model example explains, how we can retrieve selected properties of a website using SharePoint 2013 object model.

If you follow this article to retrieve website title using SharePoint 2013 object model, then here context.Load(web); will load all the properties of the website.

But suppose we need only two properties like Title and Description then it is unnecessary to bring all the properties from the server to the client. So client object model provides anonymous methods which uses lambda expressions, to specifically request property names.

The client library will query only for those properties on the server, and the server will send only those properties to the client. This technique reduces unnecessary data transfer between the client and the server.

Below is the full code:

To work with SharePoint 2013 client object model, we need to give reference to the below dlls:

  • Microsoft.SharePoint.Client.Runtime.dll
  • Microsoft.SharePoint.Client.dll

These dlls are located in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\ISAPI.

Below is the full code to retrieve the title of a SharePoint site using client object model code.

using Microsoft.SharePoint.Client;

ClientContext context = new ClientContext("http://URL of the Site");
Web web = context.Web;
context.Load(web, w => w.Title, w => w.Description);
context.ExecuteQuery();
string Title = web.Title;
string Description = = web. Description;

Add a user to a SharePoint group using SharePoint 2013 client object model

This SharePoint client object model example, we will discuss how to add a user to a SharePoint group using the SharePoint 2013 client object model.

ClientContext context = new ClientContext(“http://SiteURL”);
GroupCollection siteGroups = context.Web.SiteGroups;
// Here it will retrieve the group whose ID=1
Group myGroup = siteGroups.GetById(1);
UserCreationInformation userInfo = new UserCreationInformation();
userInfo.Email = “enjoysharepoint@gmail.com”;
userInfo.LoginName = “enjoysharepoint\\User1”;
userInfo.Title = “Admin EnjoySharePoint”;
User newUser = membersGroup.Users.Add(userInfo);
context.ExecuteQuery();

This will add the above user to the SharePoint group (myGroup) using SharePoint client object model code.

Retrieve all users from SharePoint group using client object model code

Below is the SharePoint client object model code to retrieve all users from SharePoint group.

ClientContext context = new ClientContext(“http://SiteURL”);
GroupCollection siteGroups = context.Web.SiteGroups;
// Here it will retrieve the group whose ID=1
Group myGroup = siteGroups.GetById(1);
context.Load(myGroup.Users);
context.ExecuteQuery();
foreach (User member in myGroup.Users)
{
lblUsers.Text = lblUsers.Text + “, ” + member.Title;
}

Get site level content types using SharePoint client object model


We will discuss here how to get site level content types using the SharePoint client object model.

using Microsoft.SharePoint.Client;

ClientContext context = new ClientContext("http://URL of the Site");
Web web = context.Web;
context.Load(site);
context.ExecuteQuery();
ContentTypeCollection contentTypeCollection = site.ContentTypes;
context.Load(contentTypeCollection);
context.ExecuteQuery();
foreach (ContentType contentType in contentTypeCollection)
{
Console.WriteLine(contentType.Name);
}
Console.ReadLine();

Conclusion

The client object model is very much popular nowadays in SharePoint Online or SharePoint 2010/2013/2016. We also saw various examples in SharePoint .Net client object model.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

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 SharePointSky.com

View all posts by Bijay Kumar →