XHTML Default data for a Rich Text Box - InfoPath Dev
in

InfoPath Dev

XHTML Default data for a Rich Text Box

Last post 11-17-2010 03:30 PM by Rangi. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-06-2008 12:40 PM

    XHTML Default data for a Rich Text Box

    I have two templates that are filled out in a standard order.

    The first template contains information as XHTML in a Rich Text Box.

    In the second template I would like to load the XHTML value from the first template into a Rich text box. I have no problem setting all of this up however the value displayed in the second template from the first template losses all formatting.

     I have seen some posts about having to create custom code to accomplish this however I cannot find an example of this. I am using 2007 without compatibility to 2003 so the DOM related suggestions will not work.

     Thanks for any help!!!

  • 11-17-2010 03:30 PM In reply to

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

    Re: XHTML Default data for a Rich Text Box

    Here we are. IP2003, C#.

     

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

    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 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.