SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to order by content type in a CAML query?

I seem to always get the same result no matter what I do with the Order by. Ordering by ID instead works perfectly.

query.Query = @"
                <FieldRef Name='ContentTypeId' />
                <Value Type='ContentTypeId'>0x010039EFCF9C11783C409E74551800AB7525</Value>
                <FieldRef Name='SectionTitle' />
                <Value Type='Lookup'>" + filter + @"</Value>
    <OrderBy Override='TRUE'>
        <FieldRef Name='ContentType' Ascending='FALSE' />
share|improve this question
up vote 5 down vote accepted

That looks like it should work. I know it's not optimal but, as an alternative, you could do the sorting on the client side.

var items = list.GetItems(query).OfType<SPListItem>().OrderByDescending(i => i["ContentType"]);
share|improve this answer

My understanding is that the schema of the list and fields defines whether or not a field is sortable. For ContentType field "Sortable" (that's a boolean attribute) must have been set to False.

That's the reason it is not available when you create view for your list; the field is not available in the dropdown. Same restrictions would apply to SPQuery also.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.