jueves, 26 de enero de 2012

Top 10 questions about InfoPath attachments

1. Where are InfoPath form attachments stored?

InfoPath attachments are stored as pieces of text called base64 encoded strings within the InfoPath form itself.

To be able to store a file as a string, InfoPath converts the binary data of the file to a string. This is called encoding.

Once you’ve added a file as an attachment to an InfoPath form, you can use the menu options Open or Save As on the File Attachment control to retrieve the file that was stored in the InfoPath form.

When you select either menu option, InfoPath converts the string it stored previously back to binary data and presents you with the file again. This is called decoding

2. Multi file attachment InfoPath

You can only store one file in one File Attachment on an InfoPath form; you cannot attach multiple files in the same File Attachment field.

To create a multi file attachment control in InfoPath, you can make use of a Repeating Table that has a File Attachment as one of its fields.

Perform the following steps to create a multi-file attachment in InfoPath:

  1. Add a Repeating Table with 1 column to your InfoPath form template.
  2. Go to the Data Source task pane and double-click the field under the repeating node for the Repeating Table.
  3. Change the Data type to Picture or File Attachment (base 64) and click OK.
  4. Right-click the field in the Repeating Table on the InfoPath form template, and select Change To, and then File Attachment from the context menu that appears.

That is how you can attach multiple files in InfoPath.

3. Validating event of a File Attachment control InfoPath

You can use the Validating event of InfoPath file attachments to validate things such as file names, file types, or file sizes.

For examples, see:

4. How to encode and decode a File Attachment programmatically by using Visual C# in InfoPath

While InfoPath takes care of this automatically for you when you add and retrieve attachments in InfoPath, you can also write code to do these conversions yourself.

The following figure shows the encoding and decoding stages of an InfoPath file attachment.

Encoding and decoding an InfoPath file attachment

Figure 1. Encoding and decoding an InfoPath file attachment.

Microsoft has published a KB article on how to encode and decode InfoPath file attachments.

5. InfoPath submit attachment

InfoPath attachments are technically speaking never submitted to anywhere. They are part of an InfoPath form, and the InfoPath form is submitted to somewhere.

Having said this, you can extract attachments from an InfoPath form, and store them for example in a SharePoint document library or as attachments to SharePoint list items.

For examples of InfoPath attachments and SharePoint, see:

6. SPD custom action to extract InfoPath attachments and upload to SharePoint

You can also use a custom SharePoint Designer action to extract InfoPath file attachments and then upload them to SharePoint either as attachments in a SharePoint List or documents in a SharePoint Document Library.

I created the following 2-part video tutorial that walks you through the process step-by-step:

7. Code to rename InfoPath File Attachment

To rename an InfoPath attachment, you first have to decode it, change its file name, encode it again, and then save it.

For an example, see How to programmatically rename an InfoPath file attachment.

8. Delete file attachments in InfoPath programmatically

You can delete an attachment either manually or programmatically in InfoPath; manually by using the Remove menu option on the File Attachment control, and programmatically by adding a nil attribute to the field.

The following article goes into more detail: Delete, remove, or clear an attachment from an InfoPath form.

Note: Deleting an InfoPath attachment is the same as clearing the File Attachment control.

9. File types for InfoPath attachment control

You can set the file types an InfoPath attachment field should accept by going to the Properties dialog box for the File Attachment control, selecting Allow the user to attach only the following file types, and entering the file types you want the user to be restricted to.

If you’re using InfoPath browser forms, then this option is not available and you’ll have to programmatically restrict file types for InfoPath attachments.

10. Loop through InfoPath file attachments in a workflow

To loop through InfoPath file attachments in code, you can use an XPathNodeIterator object.

I demonstrated this technique in Upload images from InfoPath to SharePoint using a custom SPD activty – Part 1.

You can locate the code for looping through InfoPath file attachments by pausing the video 5 minutes and 19 seconds into the demonstration.

Fuente:

http://www.bizsupportonline.net/blog/

No hay comentarios:

Publicar un comentario