Programmatically set the Rich Text field in infopath 2003 from InnerXML - InfoPath Dev
in

InfoPath Dev

Programmatically set the Rich Text field in infopath 2003 from InnerXML

Last post 11-17-2010 03:25 PM by Rangi. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-03-2010 05:05 PM

    Programmatically set the Rich Text field in infopath 2003 from InnerXML

    Hi,Does anyone know how to set the XHTML code read from a XML file to a Rich Text Control in InfoPath 2003.  S.Y.M. Wong-A-Ton's article mentions about using XPathNavigator which is supported with InfoPath2007 Object Model (   http://www.bizsupportonline.net/infopath2007/how-to-programmatically-get-set-xhtml-rich-text-infopath.htm). InfoPath 2003 Object Model uses IXMLDOMNode which doesn't have a property to set the innerxml retrieved through System.XML.XMLDocument from a XML file that has XHTML code.Here' my incomplete sample code XmlDocument xmlDocument = new XmlDocument();xmlDocument.Load(@"C:\RTE\RichText.xml");XmlNode rootNode = xmlDocument.DocumentElement;IXMLDOMNode domNode = thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1");domNode ??I have the XHTML code in rootNode.InnerXml, how do i use it to set mt Rich Text control.

    Any Ideas? 

    Thanks, Arvind
  • 06-03-2010 05:42 PM In reply to

    Re: Programmatically set the Rich Text field in infopath 2003 from InnerXML

    Have you tried setting domNode.xml?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-04-2010 04:53 AM In reply to

    Re: Programmatically set the Rich Text field in infopath 2003 from InnerXML

    I can't. It's a read only property.

    This one woked for me DOMDocument50 xmldoc = new DOMDocument50(); XmlNamespaceManager nm = GetNamespaceManager(); xmldoc.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-08T11-28-21' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"); xmldoc.async= false; xmldoc.validateOnParse = false; xmldoc.loadXML(xmlNode.OuterXml); domNode = (IXMLDOMNode)xmldoc;
  • 11-17-2010 03:25 PM In reply to

    • Rangi
    • Not Ranked
    • Joined on 11-16-2010
    • Posts 3

    Re: Programmatically set the Rich Text field in infopath 2003 from InnerXML

    Following is code that demonstrates the only way I could programmatically set a rich text field and retain the formatting. It is written in C#, for IP2003. It uses the clipboard ala IPC.

    Call the method like so:

    insertRichText(@"<h1>foo</h1>", "//aRichTextField");

    And here is the method:

    public void insertRichText(string richText, string xPathForInsertion)

            {

                //Declarations

                StringBuilder sb;

                IXMLDOMNode xNodeTarget;

                Encoding encoding;

                string htmlPrefix;

                string htmlSuffix;

     

                //Assignments

                xNodeTarget = thisXDocument.DOM.documentElement.selectSingleNode(xPathForInsertion);

                sb = new StringBuilder();

                encoding = Encoding.UTF8;

                htmlPrefix = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><html><head><meta http-equiv=Content-Type content=""text/html; charset={0}""></head><body><!--StartFragment-->";

                htmlSuffix = @"<!--EndFragment--></body></html>";

                htmlPrefix = string.Format(htmlPrefix, encoding.WebName);

                htmlSuffix = string.Format(htmlSuffix, encoding.WebName);

     

                //Add the top to the clip

                sb.Append(htmlPrefix);

     

                //Add the content to the clip

                sb.Append(richText);

     

                //Add the bottom to the clip

                sb.Append(htmlSuffix);

     

                //Add the clip to the clipboard

                System.Windows.Forms.DataObject clipDO = new System.Windows.Forms.DataObject();

                clipDO.SetData(System.Windows.Forms.DataFormats.Html, sb.ToString());

                System.Windows.Forms.Clipboard.SetDataObject(clipDO, true);

     

                //Select field element

                thisXDocument.View.SelectText(xNodeTarget, Type.Missing);

     

                //Paste into element

                thisXDocument.View.ExecuteAction("Paste", Type.Missing);

            }

     

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.