SP2010 and Managed Metadata and &
I’ve been doing some work with dynamically populating a Managed Metadata term store using the API and data stored in a list.
The code was quite simple - check to see if a term existed, and if not, add it. The first pass of this routine would work fine, but then the second pass would crap out with an issue:
There is already a term with the same default label and parent term.
After a bit of debugging, I figured out it was falling over on a term that contained an & (ampersand) in the name. After a further bit of debugging (converting the character to HEX) it became apparent that it’s storing it as the wide (*pretty) rendition of the ampersand. And after some further research, it would appear that this is by design!
The name value will be normailized to trim consecutive spaces into one and replace the & character with the wide character version of the character (uFF06). The leading and trailing spaces will be trimmed. It must be non-empty and cannot exceed 255 characters, and cannot contain any of the following characters ; “<>|&tab.
There are two approaches to resolving this, depending on your needs. For simple comparisons, you can use the TaxonomyItem.NormalizeName method to show you what your name will look like in the DB. You can also do some character replacements to convert the chars back. Check the links below for some code if you need it.