Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

"Design Once" and the new InfoPath 2007 Object Model

"Design Once" and the new InfoPath 2007 Object Model

  • Comments 18
One of the main design principles for InfoPath 2007 and Forms Services 2007 is that you can create your form once, write code for it once, build and publish it once, and then have it work in both the browser and the client. We call this Design Once.
To make this possible for form templates with code, we created a new object model that works on both the client and the server, so that the exact same assembly can work in both places. This is similar to what the Compact .NET Framework provides for mobile devices, where you can write a WinForm app that works on both the desktop and a Windows Mobile smartphone. Using the InfoPath object model you can write code for your form that will run the same way both on client, when opened in InfoPath, and on the server, when opened in the browser.
Getting started with System.Xml
If you've written code for InfoPath 2003, then you're used to writing code against the MSXML-based object model. For example, you might read and write a field's value like this in C# with the old object model:
string xpath = "/my:myFields/my:field1";
IXMLDOMNode field1 = thisXDocument.DOM.selectSingleNode(xpath);
string oldValue = field1.text; // Read
field1.text = "New Value";     // Write
Here's how to do the same thing using the new object model:
string xpath = "/my:myFields/my:field1";
XPathNavigator field1 = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
string oldValue = field1.Value; // Read
field1.SetValue(“New Value”);   // Write
If we break that down, we see the following mappings:
InfoPath 2003 OM
InfoPath 2007 OM
Read field1.text
Read field1.Value
Set field1.text
Set using field1.SetValue()
Compatibility: Using the old OM in InfoPath 2007
InfoPath continues to open forms that used the old object model, so you don't have to upgrade them just to use InfoPath 2007. That said, if you want a form to work in the browser, you will need to upgrade to the new object model. If you upgrade the code, InfoPath will automatically update the project format and rebind all your events, but you will need to convert your custom functions to the new OM.
Compatibility: Using the new OM in InfoPath 2003
The new object model won't work in InfoPath 2003, so we also allow you to create forms that use the old object model in InfoPath 2007. You can choose which version of the object model you want to use in Form Options in the Programmability category. 
Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
  • Note that for a database connection in InfoPath 2007, there is a separate name for the submit connection.  To get this name, modify the data connection from tools-->data connections, and walk through the wizard to the finish page - you'll see two names there - one for the query connection, and one for the submit connection.  To execute the submission, you'll need to use the code above, and use the name of the submit connection.

  • Thanx a lot for this post, it was absolutly helpfull for us!

  • Hi,

    I have two database connections in my infopath form. However, since there is a many-to-one relation between the tables, I cannot submit data through Infopath.

    I am trying to submit data through code but its not working. Can someone please help?


Page 2 of 2 (18 items) 12