So, the client side application I’ve been working on has to sync a LOT of terms to the term store, and I’ve mentioned how I had problems with Managed Metadata labels and the ampersand – and how I fixed them using TaxonomyItem.NormalizeName().
Well, that was fine, but my application was slow – so I started looking at what I could do to eliminate client side object model calls (CSOM). My suspicion was that, as the function was static, it wasn’t doing anything that I couldn’t do in my application, and save a round trip to the server.
So, I opened up reflected and decompiled Microsoft.SharePoint.Taxonomy.dll. Inside I found the code for the following:
Regex _trimSpacesRegex = new Regex(@"s+", RegexOptions.Compiled | RegexOptions.IgnoreCase); //Normalize name as Taxonomy Service does string name = _trimSpacesRegex.Replace(termName, " ").Replace('&amp;', 'uff06').Replace('"', 'uff02').Trim();
That’s much, much faster than a round trip to the server, and I learnt that speechmarks are also converted from ASCII to Unicode too.