Aidan Garnish

Collaboration Not Competition

Hiding and showing optional sections in InfoPath 2007

It is possible to add logic to InfoPath forms so that certain fields are displayed based on the value of another field. For example - if a user fills in their age on a form as being 17 or greater then the question - Do you hold a full driving license? - becomes visible. In the UK this question is not relevant if the user is less than 17.

To do this using InfoPath 2007 you will need to create a form with the two questions - How old are you? and - Do you hold a current driving license? Add a two row, two column table to your form. Add the How old are you? question in the top left box. In the top right box add a text box that takes a whole number, call it Age and set it with a default of 0.

Next, merge the two cells in the bottom row and add an optional section control. Insert a table with one row and two columns to the optional control. Add the Do you hold a current driving license? question to the table. In the right hand table cell add a drop down list box that has options of select..., Yes and No.

Set the section properties to display the section by default. You should now have something that looks like this when previewed:


Next right click on the optional section and select 'Section properties...' Select 'Display' and then 'Conditional Formatting...'

Click Add - set the condition to be Age is less than or equal to 16 and check the 'Hide this control' option.

Preview the form again and you should see:

Enter an age greater than 17 to display the optional question:

Change the age to less than 17 and the question will be hidden again.

Creating an InfoPath installer file with Visual Studio 2008

Having created an InfoPath form project using Visual Studio 2008 and adding some code behind to the form I wanted to deploy it to SharePoint. The easiest way to do this should have been to use the publishing wizard to create an installer file. However, there seems to be a bug in Visual Studio 2008 that prevents you from selecting this option in the wizard. The message displayed is that you need VS 2003 or 2005 installed to create the installer file.

There is a way around this by using the REGFORM.exe tool found in C:\Program Files\Microsoft Office\Office12. The tool allows you to create a .js file that marks the .xsn as fully trusted so that it can be added to the managed forms collection on your MOSS farm.

First you need to go to VS and the Publish option in the Build menu. Instead of selecting the create installer option publish to a network location and create the .xsn on your file system.

Next, open up a command prompt and navigate to C:\Program Files\Microsoft Office\Office12\regform.exe.

Supply the necessary parameters - these are, the /U the URN for the form which can be found in VS, File - Form Properties - ID, /T Yes to mark the form as fully trusted (this is necessary to deploy it to SharePoint) and finally the path to the .xsn file.

You should end up with something like - regform.exe /U urn:schemas-microsoft-com:office:infopath:MyForm:-myXSD-2008-08-07T13-36-16 /T Yes C:\Forms\MyForm

Running the command will create a .bak file and a .js file in the same folder as the .xsn. Run the .js file and then open SharePoint central administration. Go to the Applications tab and under the InfoPath forms services section select Manage Form Templates.

This Microsoft article explains the rest of the process to make the form available in a site collection in detail

If you run the .js in your development environment you will need to unregister the form before you will be able to open it again from Visual Studio. To do this open the .js file in Notepad and change var fInstall = true; to var fInstall = false; - Run the .js file again and this time the message prompts will tell you the form is being unregistered. You can now run the form from Visual Studio again.