Add and remove taxonomies: Remove tags

To remove a tag you will need to perform the following:

  1. Use TaxonomyManager which is the manager class for taxonomies.
  2. Lookup the tag as a FlatTaxon.
  3. Call the manager’s Delete method
  4. Call the manager’s SaveChanges method to persist the changes to the database.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Taxonomies.Tutorials
{
   public partial class TaxonomiesTutorialsSnippets
   {
       public static void RemoveTag(string name)
       {
           var taxonomyManager = TaxonomyManager.GetManager();

           //Get the taxon

           var taxon = taxonomyManager.GetTaxa<FlatTaxon>().FirstOrDefault(s => s.Title == name);

           if (taxon == null) return;

           taxonomyManager.Delete(taxon);

           taxonomyManager.SaveChanges();
       }
   }
}
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.
New to Sitefinity?