Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

InfoPath File Attachment Control

InfoPath File Attachment Control

  • Comments 21

File Attachment Control

Applies to: Microsoft Office InfoPath 2003 SP1

Microsoft Office InfoPath 2003 SP1 introduces a number of new controls.  One of these new controls, the file attachment control, enables you to insert files which will be encoded and saved with the form. This control opens up a number of new scenarios not easily possible before SP1. 

For example, let’s say that you have created a form that will be used by your sales people in the field. Typically, your sales people may track large amount of sales data in an Excel spreadsheet which includes fancy charts and pivot tables.  When these sales people report their quarterly earnings, you would like them to fill out an InfoPath form so that you can gather data such as total sales per region.  However, since the sales people have already gathered all the detailed sales data in an Excel spreadsheet, you don’t want them to have to reenter the data into the InfoPath form.  Instead, your sales people click on a file attachment control and attach the spreadsheet containing their sales data.  Later, when you are reviewing the data in the InfoPath form, you can double-click the spreadsheet file and open it in Excel in order to view the detailed sales data.

Adding a file attachment control to a form is easy.  Just follow these four basic steps:

  1. Start InfoPath and design a new blank form or design an existing form.
  2. Open the Controls task pane by clicking on the Controls link in the Design Tasks pane.
  3. Look for the File Attachment control under the File and Picture category of the Controls task pane.
  4. Insert the file attachment control by clicking on it or dragging and dropping it into the view.

Now, when you preview the form or fill out a form based on this form template, users can attach files to your form.  Also, if you open a form that has existing file attachments, you can double-click on the control to open it.  When opening files that are already attached, by default, the application that is associated with that file’s extension on your system is opened in order to view the file.


For security reasons, not all types of files can be attached to a form.  The last thing you want is for somebody to attach a malicious executable file that formats your hard drive.  For this reason, InfoPath blocks certain file types from being attached (e.g., .exe, .com, .bat, etc.).  To determine the types of files that are considered unsafe, InfoPath follows a similar model as Outlook which is documented in;EN-US;290497.

In addition to the list of file types blocked by default, you can further restrict the types of files you want users to attach to your form.  To do so, perform the following:

  1. Follow the steps above to insert a file attachment control into the view.
  2. Double-click on the file attachment control that you just inserted into your form in order to open the properties dialog for the control.
  3. On the Data tab of the properties dialog, check “Allow the user to attach only the following file types” option.
  4. In the textbox below this option, enter the extension or extensions of the file types that you want your users to be allowed to attach to the form.  Use semi-colons to separate multiple file extensions (e.g., doc; ppt; xls).

Technical Details

Upon attaching a file, InfoPath first builds a header structure which includes information about the file being attached. The structure consists of the following:

·         BYTE[4]: Signature (based on the signature for PNG):

(decimal)                       199       73         70         65
(hexadecimal)                C7        49         46         41 
(ASCII C notation)          \307      I           F          A 

The first byte is chosen as a non-ASCII value to reduce the probability that a text file may be misrecognized as a file attachment.  The rest identifies the file as an InfoPath File Attachment. 

·         DWORD: Size of the header

·         DWORD: IP Version

·         DWORD: dwReserved

·         DWORD: File size

·         DWORD: Size of file name buffer

·         File name buffer: variable size

After building the header structure described above, the header and file data are concatenated and base64 encoded.  This base64 data is then stored with the XML data in the form.  (More information about base64 encoding can be found here: 

If you wish to write code to work with InfoPath file attachments, the .NET framework provides a Convert class that includes methods to encode and decode base64 data (e.g., Convert.FromBase64String). These methods can be used to decode existing InfoPath file attachment data or to encode a file for storing in an InfoPath form.

When a file attachment control is inserted into an InfoPath form, the following processing instruction is inserted into the XML template for the form:


This processing-instruction is added as a convenience for InfoPath but is not meant to be a security feature. If this processing-instruction is removed, when users fill out the form, all file attachment controls will be disabled.

Leave a Comment
  • Please add 3 and 2 and type the answer here:
  • Post
  • While creating a tool to convert a SharePoint list to an (InfoPath) SharePoint Form Library, we discovered that needed to write out the custom InfoPath header for converted attachments. Using the information on the InfoPath team blog, we put together the a helper class with a single static method to create the blob needed inside the XML file.
  • Great info, BTW what should the signature content be? Just arbitrary data?

  • The signature must be the following 4 bytes:
    decimal: 199 73 70 65
    hexadecimal: C7 49 46 41
    ASCII C notation: \307 I F A
  • Can you build a role based (or other) security mechanism around the File Attachment Control? I mean for example, that users with certain roles can attach, modify, delete files, others can open them only in read only mode. I think that a possible solution could be to programmatically set the "allow the user to browse, delete and replace files" property.
    Thanks for your answer in advance.
  • This is nice to attach files to a form, but what can you do with them once there?  Is there any way Infopath can extract data from named cells within the spreadsheet or read the custom properties associated with the file?  How about getting them out of InfoPath?

    Seems like this functionality gets us out of the starting gate, but doesn't provide many (obvious) routes for us to take after that.
  • When a form is marked as readonly in InfoPath 2007, a file attachment can't be opened.  Any reasoning for this?  People generally need to be able to view the form (including attachments) when it's marked readonly.

  • I'm using Sharepoint 07 and Infopath 07.  When I tried to publish my form to Sharepoint including an attachment control, I get this message: "the selected field cannot be promoted because its data type is not supported: base 64binary".  When looking at changing the data type and viewing field/control properties, it doesn't appear that there are any other options for this type of field (attachment).  Is this because I am publishing a web browser form as opposed to Infopath? Any suggestions for making an attachment work with my form?  

  • Remove the field from the promoted fields list in Infopath and then try to publish.  My guess is that the form is fine except that you cannot promote a field that is an attachment type.

  • Hi all

    How can i change the default open folder for the file attachment control? When i try to attach a file via citrix throws policy errors since c drive is totally hidden from the users. File Attachment Control looks for My Documnets by default. Is there a way to change to e:\temp like that?



  • Hi sabarathnam,

    As far as I know, there is not a way to set this; however, the control should open to the last opened directory.


  • Scott

    It opens the last opened directory until the infopath is kept open. If i close infopath and open again, it defaults to My Documents.

    Thanks for your update.



  • Hi S.Saba,

    Correct - sorry I was not very clear in my last response.


  • in relations to comment posted by  jprny :

    "When a form is marked as readonly in InfoPath 2007, a file attachment can't be opened.  Any reasoning for this?...

    Disabling the attachment also causes the user not being able to view/open the attachment.

    Enabling the attachment allows a user to remove/change the attachment. Is there a way to disable the attachment from being removed/changed but able to be just viewed ?


  • PingBack from

  • PingBack from

Page 1 of 2 (21 items) 12