How do I rename a metadata term in C#?
-
09-12-2019 - |
Question
Can't find this documented anywhere. Do I just change the Term.Name and run a commit all on the term store?
Solution
Yes, that is the simplest way to do it. I have only found two ways to rename a term programmatically:
1) Set the Name property and CommitAll on the Term Store:
var site = SPContext.Current.Site;
var taxonomySession = new TaxonomySession(site);
var termStore = taxonomySession.TermStores[0];
var termGroup = termStore.Groups[0];
var termSet = termGroup.TermSets[0];
var term = termSet.Terms[0];
term.Name = "Test Update";
termStore.CommitAll();
2) Create a new Term and then Merge it with the old one.
But you were on the right track. Go with option 1. Only thing to note is that it doesn't always update instantly. It can take a few seconds for the change to be reflected when you try to retrieve the term again.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange