4

i am trying to get the comments from Comment List in a 'Descending' order , the query that i am using is :

"<Where>" +
  "<Eq>" +
    "<FieldRef Name='TopicID' /><Value Type='Text'>" + ProjectID + "</Value>" +
  "</Eq>" +
  " <OrderBy>"+
    "<FieldRef Name='Created' Ascending='False' />"+
  " </OrderBy>"+  
"</Where>";

but this query gives me the result in 'Ascending' order even if i set it to false. what is wrong here?

2
  • Ignore my previous comment - the formatting in you question didn't make me notice the wrong nesting of the tags. Commented Feb 14, 2016 at 12:07
  • you could also write it this way to avoid concatenation: $@"<Where> <Eq> <FieldRef Name='TopicID' /><Value Type='Text'>{ProjectID}</Value> </Eq> </Where> <OrderBy> <FieldRef Name='Created' Ascending='False' /> </OrderBy>"; The '$' is for the Params. The '@' is to replace concatenation
    – StiffyG
    Commented Aug 6, 2020 at 10:21

1 Answer 1

9

OrderBy should be outside of the Where clause. Try modifying your query to this:

"<Where>" +
 "<Eq>" +
    "<FieldRef Name='TopicID' /><Value Type='Text'>" + ProjectID + "</Value>" +
   "</Eq>" +
"</Where>" +
      " <OrderBy>"+
   "<FieldRef Name='Created' Ascending='False' />"+
       "</OrderBy>" ;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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