I have a company ASPX-Page with some code behind to display a treeview containing some categories. These categories are just some terms in the "Taxonomy Term Store", so only some managed metadata entries. Everything works fine and is displayed correctly, as long as no custom sort ordering is activated for these terms.

But it is a requirement that the people maintaining the terms should also be able to sort them. So if I now enable custom sorting, everything is fine, just until a new term is being added to the term store. This new entry is not shown in the treeview. I found out that the CustomSortOrder Property of the Termset is simply not being updated. So for example instead of now nine entries, the property only lists the old eight entries. This CustomSortOrder-Property keeps being wrong until I reorder the items and save the ordering again or I turn off and on the custom sort ordering once (but this messes up with my ordering and everything needs to be reordered again).

This is how my code looks:

SPSite thisSite = SPContext.Current.Site;
TaxonomySession session = new TaxonomySession(thisSite);
TermStore termStore = session.TermStores["MyTermStoreName"];
Group group = termStore.Groups["MyTermStoreGroupName"];

// (...) some treeview code

var termSet = group.TermSets["MyTermSetName"];
string sortOrder = termSet.CustomSortOrder;
if (!String.IsNullOrEmpty(sortOrder))
    // Here the sortOrder contains only the old items
    string[] termGuids = sortOrder.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

    // (...) work with the guids

Is there any way to get all the current terms instead of the old ones without messing with the ordering all the time?

1 Answer 1


I used this workaround.

if (!String.IsNullOrEmpty(sortOrder))
     List<string> termGuids = sortOrder.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToList();
     termguids.AddRange(termSet.Terms.Select(t => t.Id.ToString()).Except(termGuids));
     foreach (string guidString in termGuids)
        // some logic

I don't know if it's the best option. If there is a better answer, I will gladly accept it instead of this one.

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.