C# programmatically get all items based on Content Type using CAML query – SharePoint

The following caml query can find all items in a site collection based on content type id.

DataTable results = new DataTable();

SPSiteDataQuery q = new SPSiteDataQuery();

q.Webs = “”;

q.Lists = “”;

q.Query = “”+ctypeid+””;

 

results = web.GetSiteData(q);