Labels

2011-09-05

Extraction of embedded inline images in InfoPath 2010

At work, we needed to extract images from rich text boxes in a InfoPath 2010 form. These image files are stored to a temporary disk area and used to create a HTML preview of a document based on the XML content in the form, and also for uploading those images to a SharePoint image library, separated from their source document. In InfoPath 2010, all images are stored inline on the img-elements, in base64 encoding in the attribute xd:inline.

Our forms requires the InfoPath filler application, not web forms hosted by SharePoint. I don't think that will work. The code in the example FormCode.cs below needs full trust, since it writes to the hard disk. It's not very useful as it is written here, but it is just to illustrate the extraction mechanism.

If you upload the images to a SharePoint library like we do, you also have to add a src-attribute in the img-element, so that it points to its new address.

I don't include the form in this post, but it's simple: a rich text box with embedded images enabled, connected to one field, and a button with the id BTN_EXTRACT_IMAGES.

If images are of a more photographic nature than our images, then perhaps JPG is a better storage format than PNG.

(double click the code to copy it)