As you may already know, you can use Visual Studio Tools for Applications (VSTA) to write code for InfoPath form templates.
When you use VSTA, a project file is created for your InfoPath form template. The location of this project file is specified on the Options dialog box under the Programming category.
Unfortunately, you can only specify an absolute path for the location where to store the VSTA project corresponding to your InfoPath form template; relative paths are not allowed, so an InfoPath form template will always be tightly bound to the location of its corresponding VSTA project.
This means that you’ll have to perform extra steps after you retrieve an InfoPath project from a source control repository to get the InfoPath form template up and running with its VSTA project, that is, if you and your team members cannot or do not agree on one specific location to check out the project files to.
You’ll also have to agree with fellow team members on one method on which your team will store and retrieve InfoPath form templates and their corresponding project files from the source code repository.
In this post, I’ll outline 2 methods for storing InfoPath form templates and project files in a source control repository.
1. Store the FormCode.cs file along with the InfoPath form template
When you create a VSTA project for an InfoPath form template, InfoPath stores all of the code by default in a file called FormCode.cs, which is part of the project.
So the first method you can use to store code along with an InfoPath form template in a repository is by copying the FormCode.cs file from the project and storing it on the same location in the repository as where the InfoPath form template is located.
When another team member retrieves the InfoPath files from the source code repository, s/he would have to perform the following steps to restore the VSTA project:
- Open the InfoPath form template.
- Save the InfoPath form template to a location on disk.
- Remove any code that is bound to the InfoPath form template.
- Create a new VSTA project for the InfoPath form template.
- Replace the FormCode.cs file in the new VSTA project with the FormCode.cs file from your source code repository.
Use this method only if your VSTA project corresponding to your InfoPath form template does not contain extra files (such as for example class files) or other settings (such as for example version information in the AssemblyInfo.cs file).
If your VSTA project contains more than just code in the FormCode.cs file, it is best to use the second method for storage.
2. Store the entire project along with the InfoPath form template
While you can use method 1 described above for simple VSTA projects, you can use this method for more complex VSTA projects, which contain additional files that you need to save along with the FormCode.cs file in the project.
To simplify the process of storing the InfoPath form template along with its VSTA project you could save the VSTA project in the same folder where the InfoPath form template is located. Note: You can set the location of the VSTA project via the Programming category on the Form Options dialog box.
For example, if you save your InfoPath form template in the C:\Projects\Project1 folder, you should specify this folder as the project location in the options for the InfoPath form template.
Then when storing the InfoPath form template and its VSTA project in your source code repository, all files will be located in one main folder (C:\Projects\Project1), which you can then upload in its entirety to the source code repository.
When another team member fetches the InfoPath files from the source code repository, s/he would have to perform the following steps to get the InfoPath form template and its VSTA project to work properly:
- Open the InfoPath form template.
- Save the InfoPath form template to a location on disk.
- If required, correct the path for the VSTA project of the InfoPath form template via the Form Options dialog box.

Comments to this post were closed 30 days after it was published.