Last updated March 6, 2017
Applies to: InfoPath Designer
It is a common requirement to enable submitting multiple photos in a form. The two main complications in form design are:
- The number of photos to be captured is typically variable -- it might be a different number each time the form is submitted.
- A form will break if it contains too many photos. If the number and size of the photos exceed device capacity or bandwidth, then the form can crash or the submit can fail.
This article explains two alternative best practices for submitting multiple photos. The first uses a repeating control but limits the number of repeats, and the second submits photos a SharePoint picture library.
Collect Photos in a Repeating Section
The first instinct of a form builder is often to put a Formotus camera or annotation control inside a repeating section. This method is supported but there is a built-in danger that the form will break if the end user adds too many photos.
The solution is to limit the number of instances of the repeating section that are allowed. Here is how to set such a limit on a repeating section in InfoPath (tip of the hat to this blog post for the trick):
- Create a new integer field and add to your repeating group. For this example, we will name it count
- Right click on count and click properties, then click the function (fx) button.
- Check the box to Edit XPath (advanced) and enter in the following formula:
count(../preceding-sibling::*) + 1
- Click Verify Formula then click OK
- Make sure ‘Refresh value when formula is recalculated’ is checked
- Click OK. The count field properties should now look like this:
- If you have not added the repeating section to your form, do this now
- Select the repeating section and then click ‘Manage Rules’ in the ribbon
- Add a New/Formatting rule and mark "Don't allow users to insert or delete this control".
- Add a condition on the rule that Count is greater than or equal to the maximum number you want to allow. In the example below the limit is set at 5.
So how many photos should you allow? There's no single answer. One thing to understand is that the visual size of the photo control in the form layout determines the memory footprint of the photo for processing and submitting. So you can include more small photos or fewer large ones. It's largely a trial and error process to determine what will work on your particular devices.
Tip: When specifying the size of a camera control image, specify the width in pixels and leave the height as 'auto'. This way both portrait and landscape photos will render proportionally.
Submit Photos to a SharePoint Picture Library
It is possible to use a web service to send photos directly to a SharePoint library rather than embedding them in the form. This method is recommended when:
- Your form needs to gather more and/or larger photos than feasible using other techniques, or
- Your scenario needs photos to be individually accessible rather than embedded in a form as a base64 string
The upload process uses SharePoint's imaging.asmx Web service, a method well demonstrated in this video at bizsupportonline.com.
For a hands-on look at an implementation, you can download this InfoPath form template (XSN file). It is a proof of concept, not a polished form. Instructions and notes are located in the Description view in the form template.
Besides containing an image upload example, this experimental form also demonstrates a variety of additional features that you might wish to employ:
- The images upload individually to a picture library, then the form submits separately to a form library.
- A unique ID is shared by the form file and the picture files, so they can always be associated.
- The form constructs a URL for each picture and uses it to provide a thumbnail and a link to each picture in a repeating table in the form. Anyone viewing the submitted form can browse the thumbnails and click to the full-size pictures.