Adding an InfoPath Editor Control to a Windows Form
One of the new features of InfoPath 2007 is the ability to integrate the InfoPath editor into Windows Forms. Within Visual Studio this is done using the Microsoft.InfoPath.FormControl.dll assembly. In this example using Visual Studio 2008, we will create a simple Windows Form application that contains the InfoPath control.
Note: This example assumes that you have created a Windows Form Project
Add the InfoPath Form Control to the Toolbox
1. In the general section of the toolbox right click and select Choose Items
2. In the Choose Toolbox Items dialog select browse
3. Add the reference to the Microsoft.Office.InfoPath.FormControl.dll which by default is in the C:\Program Files\Microsoft Office\Office12
4. Once the reference is added the Choose Toolbox Items contains the reference.
5. The control is now available in the General section
Once the FormControl is added to the toolbox drag it onto the Windows Form.
Write the code
Loading an InfoPath Form Template (.xsn) can be done using the NewFromFormTemplate method of the FormControl object. As an example of this add the following code to the button.
Run the completed application and select the Load Form button to see the InfoPath form.
Comments
Anonymous
December 13, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/12/14/adding-an-infopath-editor-control-to-a-windows-form/Anonymous
December 17, 2007
I randomly get a System.AccessViolationException when we call the NewFromFormTemplate method. My customer (we've put this into production) get it more often than me and he's got a faster laptop. I can see in the stackTrace that it happens in the NewFromSolution method. Could you direct me to someone at Microsoft that would be willing to look into this?Anonymous
December 18, 2007
I haven't seen this problem myself. I would suggest that you may want to ask the questions on the MSDN forums to see if anyone may have a suggestion.