3

Trying to fetch data from SharePoint List using CAML query.

Am using the attribute Descending, but does not work as expected.

Please find the code below.

<OrderBy>
    <FieldRef Name='ID' Descending = 'True'/>
</OrderBy>

Above code still fetches the smallest ID(where ID is 1,2,3..so on), in my case it fetches the ID=1

Thanks in advance.

1 Answer 1

13

AFAIK, there is no "Descending" attribute for specifying a descending order by.

Instead, you must use the Ascending attribute, and specify "false" as the value.

<OrderBy>
    <FieldRef Name='ID' Ascending='FALSE'/>
</OrderBy>

As you can see from this page

Ascending -- Optional Boolean. This specifies the sort order on a FieldRef element that is defined in a view. The default value is TRUE.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks SPArchaeologist. Yes, You are right.. was going trough the msdn microsoft site and found the documentation for CAML(msdn.microsoft.com/en-us/library/ms442728.aspx). There is no attribute such called as Desecnding. It has only the Ascending attribute with TRUE | FALSE values. Thanks Much..
don't worry, my pleasure - It is a bit "not so intuitive". I would have preferred if they had created an attribute "Direction" with two values "Ascending" and "Descending"... Btw, just to do some random ads - there is a site specific for SharePoint questions in the stack exchange network: link here. If in the future you need anything SharePoint related and you don't receive an answer here on the main site, consider giving it a go.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.