Tuesday, September 15, 2009

Anchor tag alteration by SharePoint in Custom Field

Scenario:
Anchor tag alteration by SharePoint in Custom Field

Explanation:
Yes that is right!!

SharePoint tries to clean up all anchor tags in fields even if its a custom multicolumn field. Many experienced SharePoint developers I have spoken to about this are not aware of this.

Surprisingly it seems very awkward that Microsoft has failed to generate the altered (cleaned up according to SharePoint) HTML according to the standards properly.

The problem has occurred when I tried to add the cleaned up HTML as a node to an XML file. The generated XML therefore is invalid.

I have noticed that SharePoint actually interferes with the content that is saved into a field. A quick work around I found was to replace the characters '>', '<' and '"' with their ASCII equivalents or any other character that may be able to replace them (like ' for "). Encode the data with your custom encoding mechanism, save the data into the field, when you retrieve the data back, make sure to decode it. Code:
content.Replace("<", "<").Replace(">", ">").Replace("\"", "'");

No comments:

Post a Comment