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…