mercredi 28 janvier 2015

CustomSortOrder of TermSet is not automatically being updated on new entries



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?








0 commentaires:

Enregistrer un commentaire