Delete taxonomies
The Sitefinity CMS API enables you to delete a taxonomy. The following sample demonstrates how a taxonomy and all its children (taxa) can be deleted:
C#
using System.Linq;
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
namespace SitefinityWebApp
{
public class DeleteTaxonomiesOperations
{
/// <summary>
/// Deletes a taxonomy, including all of its taxa.
/// </summary>
/// <typeparam name="TTaxonomy">The type of taxonomy - <see cref="FlatTaxonomy"/> or <see cref="HierarchicalTaxonomy"/>.</typeparam>
/// <param name="partialTitle">Part of the taxonomy title.</param>
public void DeleteTaxonomy<TTaxonomy>(string partialTitle)
where TTaxonomy : class, ITaxonomy
{
var manager = TaxonomyManager.GetManager();
var taxonomy = manager.GetTaxonomies<TTaxonomy>().SingleOrDefault(t => t.Title.Contains(partialTitle));
if (taxonomy != null)
{
foreach (var taxon in taxonomy.Taxa)
{
manager.Delete(taxon);
}
manager.Delete(taxonomy);
}
manager.SaveChanges();
}
}
}
The method accepts a generic TTaxonomy type to support deleting both hierarchical and flat taxonomies.You must pass the taxonomy type (such as FlatTaxonomy or HierarchicalTaxonomy), as well as the title of the taxonomy you wish to delete.
NOTE: Using this method you will delete both the taxonomy and its children.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.