Insert a file attachment control

If you want users to be able to insert files on a Microsoft Office InfoPath form, you can use a file attachment control on your form template. Users can use this control to attach files to your form, and the files are then encoded and saved with the form data.

In this article

When to use a file attachment control

The user experience

Insert a file attachment control

Security details

When to use a file attachment control

Use a file attachment control when you want to:

  • Enable users to attach documents, worksheets, and other types of files to your form.

  • Attach a file to your form template, such as a file containing supplementary information about your form template.

  • Work with binary files from a database or other external data source.

In the following example, a Microsoft Office Word 2007 document is attached to an InfoPath form. The document contains details about the proposed agenda for an international sales meeting.

file attached to form via file attachment control

By default, users can browse through, delete, or replace files in a file attachment control. Users can attach any type of file to the form except potentially unsafe files that may contain viruses, such as .bat or .exe files. If you want, you can further limit the file types that users can insert in a file attachment control on your form.

Related controls

InfoPath includes controls that are similar to file attachment controls but that serve different purposes. To decide which of these controls works best on your form template, refer to the following list:

Picture control    Like a file attachment control, a picture control allows users to browse through, delete, or replace files in their forms. The difference is that you can add only picture files to a picture control, whereas a file attachment control accepts all types of files, including picture files. Both controls use the base64 data type, which is used to encode and decode binary files for storage and display.

Hyperlink    Instead of allowing users to embed files in forms, which can increase the file size of the form, you can use a hyperlink control on your form template, which enables users to insert links to the appropriate file.

Top of Page

The user experience

Depending on the options that you specified for the file attachment control, users can either insert a file in an empty file attachment control or replace a file attachment that already exists. In either case, users click inside the file attachment control to locate a file. When the Attach File dialog box appears, they can browse for a file of their choice.

You can specify exactly which types of files users can add to file attachment controls. When you specify the types of files that you want to allow, InfoPath automatically hides any unsupported files in the Attach File dialog box. For example, if you limit file attachments to .txt files, then .docx, .pptx, and other file types are hidden in the dialog box, even if they exist in the folder.

If users try to insert a file type that is potentially dangerous, such as an executable (.exe) file, a security message tells them that the file type is unsafe and prevents them from attaching it to the form. InfoPath blocks these types of unsafe files by default. For more information about unsafe files, see Security details in this article.

Top of Page

Insert a file attachment control

The procedure for inserting a file attachment control differs slightly depending on whether you are designing a new, blank form template or basing the design of your form template on a database or other external data source.

The following illustration shows how a file attachment control looks when it is selected in design mode.

File attachment control selected in design mode

Controls can be bound or unbound. When a control is bound, it is connected to a field or group in the data source so that data entered into the control is saved in the underlying form (.xml) file. When a control is unbound, it is not connected to a field or group, and data entered into the control is not saved. When you select or move your pointer over a control, text and a binding icon appear in the upper-right corner of the control. The text indicates the group or field to which the control is bound in the data source. The icon indicates whether the control is correctly bound to that group or field. When the binding is correct, a green icon appears. If there's something wrong with the binding, you'll see a blue or red icon instead.

The data source for the form template consists of fields and groups that appear in a hierarchical view in the Data Source task pane. File attachment controls are always bound to fields with a Picture or File Attachment (base64) data type. In the following example, the file attachment control on the form template is bound to the discussionItemAttachment field in the Data Source task pane.

Relationship between file attachment control on form template and corresponding field in data source

Insert a file attachment control on a new, blank form template

When you design a new, blank form template, the Automatically create data source check box in the Controls task pane is selected by default. This enables InfoPath to automatically create fields and groups in the data source as you add controls to the form template. These fields and groups are represented by folder and file icons in the Data Source task pane.

  1. On the form template, place the cursor where you want to insert the control.

  2. If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.

  3. Under Insert controls, click File Attachment.

  4. To add a label to the control, type text above or to the left of the control, followed by a colon (:).

  5. By default, users can attach any type of file to the form, except files such as .exe files, which InfoPath blocks for security reasons. To limit the types of files that users can attach to their forms, do the following:

    1. Double-click the file attachment control.

    2. Click the Data tab.

    3. Under Validation and Rules, select the Allow the user to attach only the following file types check box, and then, in the box, type the file extensions for the file types that you want to allow. For example, if you type .docx, users can only attach Office Word 2007 files to the file attachment control on their form.

      Note: If you are designing a browser-compatible form template, you won't be able to specify which file types are allowed in the file attachment control.

  6. By default, a file attachment icon with placeholder text is inserted onto the form template.

  7. To show a default fle attachment inside the control instead of the placeholder text, do the following:

    1. Double-click the file attachment control.

    2. Click the Data tab.

    3. Under Binding, click Specify default file, and then click Browse.

    4. In the Attach File dialog box, select the file that you want to appear inside the file attachment box on the form template, and then click Insert.

Insert a file attachment control on a form template that is based on an existing data source

If you base the design of your form template on an existing Extensible Markup Language (XML) file, database, or Web service, InfoPath derives the fields and groups in the Data Source task pane from that existing data source. In this scenario, you can insert a file attachment control by dragging a field from the Data Source task pane onto the form template or by inserting a file attachment control from the Controls task pane instead, as described in the following procedure:

  1. On the form template, place the cursor where you want to insert the control.

  2. If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.

  3. Under Insert controls, click File Attachment.

  4. In the File Attachment Binding dialog box, select the field in which you want to store file attachment data, and then click OK.

  5. InfoPath uses the name of the field or group as the control's label. If necessary, change the label text.

  6. By default, users can attach any type of file to their form, except files such as .exe files, which InfoPath blocks for security reasons. To limit the types of files that users can attach to their forms, do the following:

    1. Double-click the file attachment control.

    2. Click the Data tab.

    3. Under Validation and Rules, select the Allow the user to attach only the following file types check box, and then, in the box, type the file extensions for the file types that you want to allow. For example, if you type .docx, users can only attach Office Word 2007 files to the file attachment control on their form.

      Note: If you are designing a browser-compatible form template, you won't be able to specify which file types are allowed in the file attachment control.

  7. By default, a file attachment control with placeholder text is inserted onto the form template.

  8. To make a default file appear on the form template instead of the placeholder text, do the following:

    1. Double-click the file attachment control.

    2. Click the Data tab.

    3. Under Binding, click Specify default file, and then click Browse.

    4. In the Attach File dialog box, select the file that you want to appear inside the file attachment box on the form template.

      Tip: You can also use the Data Source task pane to insert controls. In the Data Source task pane, right-click the field that you want to bind the file attachment control to, and then click File Attachment on the shortcut menu. If you do not see File Attachment as a choice on the shortcut menu, make sure that the field has a picture or file attachment data type.

Top of Page

Security details

InfoPath does not allow certain file types, such as .exe, .com, or .bat files, to be attached to a form. This restriction helps to prevent malicious executable files from adversely affecting users' computers. To determine the types of files that are considered unsafe, InfoPath follows a model similar to that of Microsoft Office Outlook.

By default, the following file extensions are considered unsafe by InfoPath: .ade, .adp, .app, .asp, .bas, .bat, .cer, .chm, .cmd, .com, .cpl, .crt, .csh, .der, .exe, .fxp, .hlp, .hta, .inf, .ins, .isp, .its, .js, .jse, .ksh, .lnk, .mad, .maf, .mag, .mam, .maq, .mar, .mas, .mat, .mau, .mav, .maw, .mda, .mdb, .mde, .mdt, .mdw, .mdz, .msc, .msh, .msh1, .msh2, .msh1xml, .msh2xml, .mshxml, .msi, .msp, .mst, .ops, .pcd, .pif, .plg, .prf, .prg, .pst, .reg, .scf, .scr, .sct, .shb, .shs, .tmp, .url, .vb, .vbe, .vbs, .vsmacros, .vsw, .ws, .wsc, .wsf, .wsh.

System administrators can add file types to this list by adding a certain registry key and setting its value to a semicolon-delimited list of extensions. They can also remove files from the unsafe list.

Top of Page

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!

×