Use Visual Studio to create InfoPath forms… without code

Although the primary purpose of Visual Studio 2005 Tools for Office (InfoPath 2007 Support) is to add C# and Visual Basic code to your InfoPath form template, you can still take advantage of hosting InfoPath inside Visual Studio to design forms that don't have any code.

 

When you create a new InfoPath form template project in Visual Studio, by default, it will be created with code enabled.  To obtain a form without code, you need to explicitly remove the code from the form by using the remove code button in the programming tab of the form options dialog.

 

 

After clicking on this button, you might be confused to see that the code file is still present in the project.  Don’t worry about this.  When you build the project, the hosted designer will not add the output assemblies to the form template.

 

How it works

After a new project is created, the “enabled” attribute of the “managedCode” element in the manifest.xsf defaults to “yes”.  Clicking the remove code button sets this attribute to “no”.

 

<xsf2:managedCode … enabled="no"></xsf2:managedCode>

 

This attribute is set back to “yes” when you insert an event handler using the hosted InfoPath designer.

 

After a success build, the output assemblies will only be included with the form template when this attribute is set to yes.

 

- Gary

Software Development Engineer