2

I am using SDL Tridion 2013 SP1 and using the Core Service to retrieve all the categories in the SDL Tridion system. Below is my code:

TaxonomiesFilterData taxFilter = new TaxonomiesFilterData();
taxFilter.SortExpression = "Title";
XElement items = client.GetListXml("tcm:0-10-1", taxFilter);

Here client is a SessionAwareCoreServiceClient client and tcm:0-10-1 is a valid Publication ID

I am able to retrieve all the categories in the publication successfully, however, the issue is that they are not in a Sorted order as I wish to get them in sorted by their title (same as it happens in the CME).

Further, I have even tried using the Item Selector Community extension (created by Bart) but I am also getting the same result (non-sorted list of categories).

Any help will be highly appreciated.

3

Just use

var items = client.GetList("tcm:0-10-1", taxFilter);

And then

var orderedItems = items.OrderBy(i => i.Title);
| improve this answer | |
  • Thanks; although I was looking for some way to sort this out through the core service itself - I wish SortExpression or something like that would be of some help. I really do not wish to sort it after retrieving the result. – Pankaj Gaur Jan 2 '15 at 11:11
  • Why? It will even be faster. And we are talking about relatively small amount of items. I doubt you have more than few hundred categories. Also, as it's Linq it will only sort it when necessary – Andrey Marchuk Jan 5 '15 at 15:03
0

I am not sure, if taxFilter.SortExpression = "Title"; works at all. I have tried it with TaxonomiesFilterData and CategoriesFilterData and its not working like above (setting a field name as a sort expression ).

But if you want to use GetListXml not GetList as suggested in anothee answer by @user978511, you can use CategoriesFilterData inplace of TaxonomiesFilterData, as it returns the categories sorted by title by default.

I know its not the best option but could be useful.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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