InfoPath Solutions Blog

Blog about InfoPath and related technologies such as SharePoint, .NET, and other Microsoft software products.

How to open an InfoPath form and template that were moved or copied

Published on Wednesday, 10 March 2010 by S.Y.M. Wong-A-Ton

Problem

Your client had an InfoPath developer (someone you do not know) build an InfoPath form template and then publish it to a SharePoint server at your client’s site.

You do not have access to the SharePoint server where the form template was published, neither do you have direct access to the InfoPath form template the other person created and deployed to SharePoint.

To keep this scenario simple, let’s assume that the InfoPath developer did not add code to the InfoPath form template, so you’re dealing with a codeless InfoPath form template that was deployed to a SharePoint Form Library.

The InfoPath form template is not doing exactly what your client wants it to do, and the InfoPath developer has since left the company.

Now your client wants you to take a look at the form template and troubleshoot the form template and an XML file that was created using that form template, so your client sends you both the XML file and the original InfoPath form template that was deployed to SharePoint.

Now when you try to open the InfoPath form, you get the following error message:

InfoPath cannot open the following file: <InfoPath_Form_File_Name_And_Path>.
The following form template for the form cannot be found:

http://<SharePoint_Server_Name>/<SharePoint_Site_Name>/<SharePoint_Form_Library_Name>/forms/template.xsn

And when you try to open the InfoPath form template in Design mode, you get the following warning:

The form template was published to one location and has been saved or moved to a different location. To ensure that forms based on this template work correctly, publish the template again.

Solution

I’ve briefly touched upon how InfoPath form templates and InfoPath forms are related in the video tutorial Creating a simple InfoPath form template, but I’ll recap the essence of the story here.

An InfoPath form is an XML file that is based on an InfoPath form template (an XSN file). The XSN file contains all of the code and logic for an InfoPath form to be filled out through either the InfoPath client application or through a browser via SharePoint.

This means that the two always go together: To open an InfoPath form, you always have to have an InfoPath form template published somewhere. In essence, an InfoPath form is linked to its corresponding InfoPath form template.

But because an InfoPath form is just an XML file (so a text file), you can open it in Notepad to relink it to a different InfoPath form template that has the same structure and version as the original form template from which it was created.

So to fix the problem described above, you must do two things:

  1. Save the form template to your own computer (so that you can troubleshoot it) from within the InfoPath client application.
  2. Change the InfoPath form to point to the template you saved on your own computer.

Fixing InfoPath form templates that have been copied or moved

When an InfoPath form template has been moved or if you receive one that was saved or published to a different location than where it is currently located, all you have to do is open it, save it, and then republish it.

To correct an XSN (InfoPath form template) that has been moved or copied:

  1. In Windows File Explorer, right-click the InfoPath form template (XSN), and choose Design from the context menu that appears.
  2. When the InfoPath form template opens in InfoPath, click OK to close the warning message.
  3. On the File menu, click Save As, and save the InfoPath form template locally somewhere on disk.

The XSN should now open without any warnings, and you should be able to publish it.

Fixing forms that are linked to templates that have been moved

When an InfoPath form template that an InfoPath form is linked to is moved or cannot be found, you have to relink the InfoPath form to point to the InfoPath form template that has been published to a new location.

To relink an InfoPath form to an InfoPath form template that was moved and republished:

  1. Open the InfoPath form in Notepad.
  2. Change the href attribute in the mso-infoPathSolution processing instruction to point to the correct location for the newly published InfoPath form template.

    InfoPath form processing instruction with the InfoPath form template the InfoPath form is linked to highlighted in yellow and the version number highlighted in green

    Figure 1. InfoPath form processing instruction with the InfoPath form template the InfoPath form is linked to highlighted in yellow and the version number highlighted in green.

  3. If the version number of the newly published InfoPath form template differs from the original InfoPath form template of the InfoPath form, change the solutionVersion attribute to be the same as the newly published InfoPath form template.

You should now be able to open the InfoPath form without any warnings or errors.

Note:
Every time you save or publish an InfoPath form template, its version number is automatically increased.

InfoPath form template version number on the Form Options dialog box

Figure 2. InfoPath form template version number on the Form Options dialog box.

If you link an InfoPath form to an InfoPath form template that is of a newer version than the template the InfoPath form was originally created from, you’ll get the following warning message:

This form was created with a new version of the form template. InfoPath cannot find the new version. Do you want to open with the older version?

How to set the maximum field length in InfoPath

Published on Monday, 1 March 2010 by S.Y.M. Wong-A-Ton

If you’re used to programming in Visual Studio, you’ll be disappointed to know that there is no MaxLength property that you can set on fields in InfoPath that can hold multiple lines of text with line breaks.

So if you want to set the maximum field length on a multi-line InfoPath Text Box (that allows line breaks) or Rich Text Box, you must use data validation.

Note: You can limit the amount of characters on a single-line text box by going to the Properties dialog box of the text box, clicking on the Display tab, and selecting the Limit text box to checkbox.

When using data validation to restrict the maximum field length in InfoPath, you can use the string-length function in a The expression data validation condition to check whether the amount of characters entered in a field is greater than the maximum characters allowed, and then display an error message.

For example, in Figure 1, I’ve created a data validation condition to check whether the maximum length of a piece of text in a multi-line text box (field1) exceeds 10 characters. This technique also works for rich text boxes in InfoPath.

Caveat: Spaces and line breaks are counted as characters.

Data validation condition to check maximum field length in InfoPath

Figure 1. Data validation condition to check maximum field length in InfoPath.

Now whenever you type more than 10 characters into the field that has the data validation set on it, you’ll see a red border appear. And if you hover over the field, a tooltip containing the error message will appear as shown in Figure 2.

Error message in InfoPath when the maximum field length is exceeded

Figure 2. Error message in InfoPath when the maximum field length is exceeded.

Quick Tip: Display button text on two lines in InfoPath

Published on Monday, 22 February 2010 by S.Y.M. Wong-A-Ton

Once in a while I go through the log files of my InfoPath website and sometimes I find some interesting things that InfoPath or SharePoint users want to do with Microsoft products.

Recently I found the following search query in my logs: button text infopath two lines.

While it is not always clear to me what a searcher is/was looking for, sometimes the queries are descriptive enough that I can get an idea of what a person is trying to do.

So I decided to have a bit of fun today and write a post about how you can place the text that goes on a button – more officially called a "label" – on two lines on the button in InfoPath. It’s kind of a workaround, but I hope you’ll find this solution useful.

To display button text on two lines in InfoPath and create a multi-line label:

  1. Create an XML file that has the following contents (with the line-breaks exactly as you see them here on the screen):

    <?xml version="1.0" encoding="UTF-8" ?>
    <label>Line 1
    Line 2
    </label>

  2. In InfoPath, create a Receive data connection to an XML document, and specify the XML file you created in the previous step.
  3. Add a button to your InfoPath form template and use the formula button behind the Label field on the Button Properties dialog box to set the value of the button’s text to the label node of the secondary data source to the XML file.

    Selecting the label node in the secondary data source to the XML file containing the multi-line button text

    Figure 1. Selecting the label node in the secondary data source to the XML file containing the multi-line button text.

The resulting multi-line button label is shown in Figure 2 with the button text spanning two lines.

Multi-line button text in InfoPath

Figure 2. Multi-line button text in InfoPath.

This solution works for InfoPath forms that are filled out through the InfoPath client application and through a browser.

Working with InfoPath