This article contains a sample on how to alphabetize taxonomy order in the CMS using the Ektron framework API.
This is the sample using the TaxonomyManager as seen here.
protected void uxSubmit_Click(object sender, EventArgs e)
{
try
{
Ektron.Cms.Framework.Organization.TaxonomyManager taxonomyManager = new Ektron.Cms.Framework.Organization.TaxonomyManager();
//Ektron.Cms.API.Content.Taxonomy taxAPI = new Ektron.Cms.API.Content.Taxonomy();
//Ektron.Cms.TaxonomyRequest taxonomyReq = new Ektron.Cms.TaxonomyRequest();
//taxonomyReq.TaxonomyId = Objectvalue;
//taxonomyReq.TaxonomyLanguage = 1033;
//taxonomyReq.IncludeItems = true;
//taxonomyReq.Depth = 1;
//taxonomyReq.SortOrder = "taxonomy_item_display_order";
//taxonomyReq.SortDirection = "Ascending";
//Ektron.Cms.TaxonomyData taxData = taxAPI.LoadTaxonomy(ref taxonomyReq);
// We query the DB for the taxonomy that exists in the DB as displayed in the workarea.
Ektron.Cms.TaxonomyData taxData = taxonomyManager.GetTree(89, 1, false, null, Ektron.Cms.Common.EkEnumeration.TaxonomyType.Content, Ektron.Cms.Common.EkEnumeration.TaxonomyItemsSortOrder.taxonomy_item_display_order);
// We then sort that list by name to have an alphabetical order
List sortedTaxData = taxData.Taxonomy.OrderBy(x => x.Name).ToList();
// This code here will take the sorted order and call ReOrder on each item in the list giving it the new position.
int pos = 1;
foreach (Ektron.Cms.TaxonomyData t in sortedTaxData)
{
taxonomyManager.Reorder(Convert.ToInt64(t.Id), pos, false);
//Response.Write(" Tax ID: " + t.Id + " pos: " + pos);
pos++;
}
}
catch (Exception ex)
{
}
}
Please sign in to leave a comment.