Tuesday, May 21, 2013

Get list level content types using SharePoint 2010 client object model

In this post we will discuss about how to get list level content types using SharePoint 2010 client object model. Also you can check my previous posts on:

- Get all first level subsites under website in SharePoint 2010

- Tutorial on Microsoft Office 365

- Call jQuery to SharePoint page using Custom Action

To work with SharePoint 2010 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\14\ISAPI.

Full Code:

using Microsoft.SharePoint.Client;

ClientContext context = new ClientContext("http://URL of the Site");

Web web = context.Web;

context.Load(site);

context.ExecuteQuery();

List list = site.Lists.GetByTitle("MyListName");

context.Load(list);

context.ExecuteQuery();

ContentTypeCollection contentTypeCollection = list.ContentTypes;

context.Load(contentTypeCollection);

context.ExecuteQuery();

foreach (ContentType contentType in contentTypeCollection)
{

 Console.WriteLine(contentType.Name);

 }

Console.ReadLine();

No comments:

Post a Comment