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.

2 Answers 2

3

Just use

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

And then

var orderedItems = items.OrderBy(i => i.Title);
2
  • 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. Commented Jan 2, 2015 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 Commented Jan 5, 2015 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.

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.