InfoPath 2007 Winforms Host

A new feature in InfoPath 2007 is the ability to host an InfoPath form.  The below shows how that host can handle the submit event from the InfoPath form.  Note this post assumes the reader has some InfoPath development exposure.

1.  Firstly install InfoPath 2007.  Then create a Winforms Visual Studio project and add a reference to Microsoft.Office.InfoPath.dll and Microsoft.Office.Interop.InfoPath.xml.dll.  The interop dll allows us to interact with the xml content of the InfoPath form.  Also add the Microsoft.Office.InfoPath.FormControl user control.  Your references should look as below when done.


2.  Now open InfoPath Designer.  Add a new submit data connection and select the host application option as seen below.

3.  Now set the submit options as follows.

4.  Now place a button control on the form and give it a submit action.

5.  Lets write some code!  You’ll notice the first thing the solution does is set the submit event handler, then uses the NewFromFormTemplate method to create a new document instance within the  InfoPath FormControl.  The submit event handler simply casts the sender object to a InfoPathEditorObjectClass that allows me to interact with the DOM.  DOM.xml provides the XML instance which I just display via a message box.

6.  And here it is!  All done in about seven lines of code…

This entry was posted in InfoPath. Bookmark the permalink.

One Response to InfoPath 2007 Winforms Host

  1. Herb F says:

    One problem with this is that the Tab key will not allow you to move between controls within the InfoPath form. It seems the WinForm is intercepting it to handle it, but the InfoPath control that is hosted never gets the event.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s