A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Sunday, February 3, 2008

InfoPath: Copying content of one section to another

If you have two sections (sections can have anything including file controls) and you want to copy content from one section to another, here is how you do it:
string sourceXPath = "/my:myFields/my:Source";
string destXPath = "/my:myFields/my:Destination";
 XPathNavigator source = this.CreateNavigator().SelectSingleNode(srcXPath, this.NamespaceManager);
            XPathNavigator dest = this.CreateNavigator().SelectSingleNode(destXPath, this.NamespaceManager);
            if (dest.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
                dest.DeleteSelf();
            if (source.InnerXml.Contains("xsi:nil="))
            {
                //Do nothing
            }
            else
            {
                if (dest.InnerXml.Contains("xsi:nil="))
                {
                    dest.InnerXml = source.InnerXml;
                }
                else
                {
                    dest.InnerXml += source.InnerXml;
                }