Tuesday, February 5, 2013

Importing terms with Ampersand (&) to Managed Metadata

When working on populating the term store in SharePoint 2013 with some data from a CSV file via PowerShell I encountered a weird issue with ampersands.

Importing works just fine, but when running the script the second time where it should not create nodes already existing, it still tried to re-add all terms with an ampersand in them.

Reading the post SharePoint 2010 Managed Metadata Import Ampersand by David Winchurch explains that ampersands are getting unicode encoded during import, hence comparison with the non-unicode version will fail.

Fortunately there is a helper method TaxonomyItem.NormalizeName which will trim consecutive spaces to one as well as encode ampersands, and it works equally well in 2013 as in 2010.

You gotta love all the special quirks in SharePoint Open-mouthed smile