private void SaveTags() { string tags = new PortalSecurity().InputFilter(_Tags, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting); tags = HttpContext.Current.Server.HtmlEncode(tags); if (!string.IsNullOrEmpty(tags)) { foreach (string t in tags.Split(',')) { if (!string.IsNullOrEmpty(t)) { string tagName = t.Trim(' '); Term existingTerm = (from term in ContentItem.Terms.AsQueryable() where term.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select term).SingleOrDefault(); if (existingTerm == null) { //Not tagged TermController termController = new TermController(); Term term = (from te in termController.GetTermsByVocabulary(TagVocabulary.VocabularyId) where te.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select te). SingleOrDefault(); if (term == null) { //Add term term = new Term(TagVocabulary.VocabularyId); term.Name = tagName; termController.AddTerm(term); } //Add term to content ContentItem.Terms.Add(term); termController.AddTermToContent(term, ContentItem); } } } } IsEditMode = false; //Raise the Tags Updated Event OnTagsUpdate(EventArgs.Empty); }