Search SharePoint 2010 Managed Metadata Terms with an Ampersand

Already struggling with the poor functionality of the web service interface of the Taxonomy web service of SharePoint 2010, I stumbled upon another challenge.

I was building a MS CRM 2011 Plugin that populates the SharePoint Term Store using the Taxonomy web service (http://<sharepointurl>/_vti_bin/TaxonomyClientService.asmx).
The first problem was the poor functionality of the web service like being unable to add Labels to Terms.
This cannot be fixed worked around.

Then I had to query SharePoint for a Term that contained an ampersand.
Adding the Term was not a problem when the XML was escaped properly.

string _newterm = “V&D”;

_newterm = _newterm.Replace(“&”, “&amp;”).Replace(“<“, “&lt;”).Replace(“>”, “&gt;”).Replace(“\””, “&quot;”).Replace(“‘”, “&apos;”);

 

But when the SharePoint is queried for a certain Term… it works slightly different.

The TermStore can be queried for example using “GetTermsByLable()”

 

string TermXml = SPTaxService.GetTermsByLabel(TermLabel,

1033,


StringMatchOption.ExactMatch,

10,

NewTermXml,


false);

 

When you send use the TaxonomyClientService.asmx, the service will not find your term, even though when you created it you used the exact same string.

The reason is that an & will be stored by SharePoint as \uFF06

So when you wanna search for a Term, make sure you replace the ampersand… like…

 

string XmlTerm = “<newTerms><newTerm label=\”” + _newterm.Replace(“&”, “\uFF06”) + “\” clientId=\”1\” parentTermId=\”” + Guid.Empty + “\”></newTerm></newTerms>”);

 

The weird thing is, that the VS2010 Debugger still will show you the &amp;
The result from SharePoint is the right one…

So …replacing the & with &amp; does not work..!

3 thoughts on “Search SharePoint 2010 Managed Metadata Terms with an Ampersand

  1. Hi there, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments?

    If so how do you reduce it, any plugin or anything you can advise?
    I get so much lately it’s driving me insane so any help is very much appreciated.

    • My blog is hosted by WordPress… I think WP blocks pretty much everything that is SPAM.
      Good luck with your spam-issue.

      IvoB

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s