Wednesday, September 11, 2013

SharePoint 2013/2016: HTML Entity Codes in Rich Text List Columns

Recently I ran into a problem attempting to programatically replace characters within a rich text list column from a SharePoint 2010 workflow activity in SharePoint 2013. The replacement characters are identified by being placed in curly brackets (e.g. {ReplaceMe}). The code that used to run in SharePoint 2007 no longer did.

In investigating the stored string value of the list item, I noticed that the brackets were being replaced with ASCII-based HTML entity codes. Therefore the replace statement would never find {ReplaceMe} since it was in the retrieved string as {ReplaceMe}. Since there are possibly hundreds of workflows that already look for values based on the brackets, I needed to actually replace the brackets in what workflow was looking for with the HTML entity codes.

Lucky enough retrieving these values using the object model (SPList, SPQuery, etc.), seems to convert the string back to the friendly version as I also had an email console app that did a similiar find and replace from a rich text list field and that continued to work without any modifications.
However, it still worked because I was using HttpUtility.HtmlDecode when retrieving the value from the list item.

So basically, using the HttpUtility.HtmlDecode will prevent any mishaps but, just in case, I wanted to document the HTML Entity Codes that are used within SharePoint 2013 Rich Text Fields:

CharacterHTML Entity CodeName
{ { Left Curly Bracket
} } Right Curly Bracket
& & Ampersand
< &lt; Less Than
> &gt; Greater Than
: &#58; Colon
" &quot Double Quotes

No comments:

Post a Comment

Matched Content