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:
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.
Security
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 http://support.microsoft.com/default.aspx?scid=kb;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:
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: http://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html.)
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:
<?mso-infoPath-file-attachment-present?>
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.
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?
thanks
S.Saba
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.
regards
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 ?
Manin...
PingBack from http://www.hilpers.com/868563-infopath-dateianlgen-auswerten
PingBack from http://www.keyongtech.com/1237099-extracting-embedded-file-attachments