Set partially bold text

19/10/2015 10:50

There is no way how to set default text value formatted in InfoPath, but we can do it in a code. In following example I have one field of RichText type

Here is a code, how to insert partially bold text


 using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;

namespace Form1
    public partial class FormCode
        public void InternalStartup()
            //ok, plain text
            //XNode("/my:myFields/my:RichTextField").SetValue("Hello World."); //ok

            //renders tags
            //XNode("/my:myFields/my:RichTextField").SetValue("<strong xmlns=''>Lukas </strong> born <strong xmlns=''>8.8.1979.</strong>");

            //renders formatted text
            XNode("/my:myFields/my:RichTextField").InnerXml = "<strong xmlns=''>Lukas </strong> born <strong xmlns=''>8.8.1979.</strong>";//renders formatted text

            //throws exception
            //XNode("/my:myFields/my:RichTextField").InnerXml = "<strong>LLukas </strong> born <strong>8.8.1979.</strong>";//throws exception

        private XPathNavigator XNode(string xpath)
            XPathNavigator node = DataSources[0].CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
            return node;