I just tested this in a Console Application:
static void Main(string[] args)
{
using (var context = new ClientContext(webUrl))
{
// 1 - Find items in a List by Content Type
string contentTypeName = "Event";
string listName = "Calendar 2";
ListItemCollection items = FindItemsWithContentType(context, listName, contentTypeName);
// 2 - Find all Lists that Contain Content Type and Items of that Content Type
ListCollection siteLists = w.Lists;
context.Load(siteLists);
context.ExecuteQuery();
foreach (var list in siteLists)
{
if (CheckForContentTypeInList(context, list.Title, contentTypeName) == true)
{
Console.WriteLine(list.Title + " Contains Content Type");
items = FindItemsWithContentType(context, list.Title, contentTypeName);
}
}
}
}
private static ListItemCollection FindItemsWithContentType(ClientContext context, string listName, string contentTypeName)
{
Web w = context.Web;
var query = new CamlQuery()
{
ViewXml = String.Format("<View><Query><Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>{0}</Value></Eq></Where></Query></View>", contentTypeName)
};
List list = w.Lists.GetByTitle(listName);
ListItemCollection items = list.GetItems(query);
context.Load(items);
context.ExecuteQuery();
return items;
}
private static bool CheckForContentTypeInList(ClientContext context, string listName, string contentTypeName) {
Web w = context.Web;
ContentTypeCollection contentTypes = w.Lists.GetByTitle(listName).ContentTypes;
context.Load(contentTypes);
context.ExecuteQuery();
foreach (ContentType ct in contentTypes)
{
if (ct.Name == contentTypeName)
{
return true;
}
}
return false;
}