InfoPath – Programatically set values for the Rich Text field from SharePoint List


-  Populating the rich text field content from SharePoint List to the InfoPath form's Rich Text field


-  The InfoPath form's rich text field won't recognize the contents read from SharePoint list's rich text field as valid XML. The SharePoint list's rich text field storest the raw html (malformed) which is not compatible with XML.


-  The SharePoint list's rich text field contents needs to be parsed/converted to a well-formed HTML so that the XML can recognize without any validation errors.

-  The malformed HTML can be converted to a well-formed XML compatible using the codeplex tool HTMLAgilityPack.

Code Snippet:

// Instantiate the HtmlDocument instance from HtmlAgilityPack

HtmlDocument commentsDoc = new HtmlDocument();


commentsDoc.OptionOutputAsXml =




HtmlNodeCollection nodes = commentsDoc.DocumentNode.SelectNodes("//div[@class!='']");



if (nodes != null)




foreach (HtmlNode node in nodes)






nodes =


commentsNode.InnerXml =

"<div xmlns=''>" + commentsDoc.DocumentNode.InnerHtml + "</div>";

Comments (1)

  1. Chip says:

    Excellent Post. Worked like a dream.

    Many Thanks

Skip to main content