What does TaxonomyItem.NormalizeName() do?

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('&', '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.

Advertisements
What does TaxonomyItem.NormalizeName() do?

4 thoughts on “What does TaxonomyItem.NormalizeName() do?

  1. And people like to complain that REST is “chatty”.

    This stuff should be offered as clearly documented JavaScript functions. Maintained, upgraded, etc. it makes no sense to send that off to the server.

    M.

    Like

  2. Martin says:

    There’s also an error on the regex function, hopefully this comment works and helps people out:

    Regex _trimSpacesRegex = new Regex(@”\s+”, RegexOptions.Compiled | RegexOptions.IgnoreCase);
    //Normalize name as Taxonomy Service does
    string normalizedName = _trimSpacesRegex.Replace(childElement.Attribute(“Name”).Value, ” “).Replace(‘&’, ‘&’).Replace(‘”‘, ‘"’).Trim();

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s