2 Ways to store InfoPath VSTA projects in a source control repository

Learn which 2 methods you can use when you create an InfoPath form template that is bound to a VSTA project and want to store the files in and then later fetch the files from a source control repository such as e.g. Visual SourceSafe.

ADVERTISEMENTS

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:

  1. Open the InfoPath form template.
  2. Save the InfoPath form template to a location on disk.
  3. Remove any code that is bound to the InfoPath form template.
  4. Create a new VSTA project for the InfoPath form template.
  5. 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:

  1. Open the InfoPath form template.
  2. Save the InfoPath form template to a location on disk.
  3. If required, correct the path for the VSTA project of the InfoPath form template via the Form Options dialog box.
 
 Subscribe via RSS or Email

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners
InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013
InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners
InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010
InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers
InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services


Related Posts

ADVERTISEMENTS

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services