The Case of the Missing PI - Greg Collins

InfoPath Dev

This Blog


Greg Collins

The Case of the Missing PI

DAY 1 (2004-06-24)

I was just working with a set of forms where a non-managed code (i.e. JScript)—hereafter referred to as NMC—form launches a managed code (i.e. C#)—hereafter referred to as MC—form and passes in its data using the new InfoPath 2003 SP1 method NewFromSolutionWithData. I ran into a bug that I have Microsoft tracking down as I write.

The problem occurs only when managed code is involved. It is related to the Preview version of InfoPath 2003 SP1. I expect it will be fixed in the release version of SP1.

If I use the NewFromSolutionWithData method going from a NMC form to another NMC form, then the problem does not present itself. But if I go from a NMC form to a MC form, or if I got from a MC form to either a NMC or MC form, the problem appears.

So what exactly is the problem? The problem is that 2 of the 3 processing-instructions (PIs) that appear at the top of an InfoPath .xml file get striped out, namely the PI and the PI.

Missing the former PI is not a great loss, but without that latter PI, Windows does not know that the .xml file belongs to InfoPath and will therefore not attempt to open it using InfoPath. Also this will result in the .xml file not having the InfoPath icon to identify it.

Luckily, most InfoPath developers will not encounter this situation. A possible work around, if you know you will get hit by this bug, is to use the OnLoad event handler to manually add the missing PIs back into the XML. I haven't tested this yet, but believe it will work.

DAY 2 (2004-06-25)

Having played around a little with the code, my initial hunch was correct, there is a workaround and it is using code. This will require that you establish some way of knowing that your form was opened using the NewFromSolutionWithData method, and then in the OnLoad event handler you can add the following code:

IXMLDOMProcessingInstruction oXML = thisXDocument.DOM.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
IXMLDOMProcessingInstruction oPI = thisXDocument.DOM.createProcessingInstruction("mso-application", "progid=\"InfoPath.Document\"");
thisXDocument.DOM.insertBefore((IXMLDOMNode)oPI, thisXDocument.DOM.firstChild);
thisXDocument.DOM.insertBefore((IXMLDOMNode)oXML, thisXDocument.DOM.firstChild);

var oXML = XDocument.DOM.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
var oPI = XDocument.DOM.createProcessingInstruction("mso-application", "progid=\"InfoPath.Document\"");
XDocument.DOM.insertBefore(oPI, XDocument.DOM.firstChild);
XDocument.DOM.insertBefore(oXML, XDocument.DOM.firstChild);

Thus, when the form is saved, the two missing PIs will be back in place and your form will be ready to roll.

©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on


No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.