Use a custom SharePoint Designer workflow activity to upload images from InfoPath to a SharePoint Picture Library
Learn how you can use an InfoPath browser form, file attachment controls in a repeating table, and a custom SharePoint Designer workflow activity to upload and store images in a SharePoint Picture Library.
This article applies to InfoPath 2007 with SharePoint 2007. If you are using InfoPath 2010 with SharePoint 2010 or InfoPath 2013 with SharePoint 2013, you can upload images to a SharePoint picture library without having to write code.
To upload images from an InfoPath form to a SharePoint Picture Library, you could use either a SharePoint workflow (Visual Studio workflows or SharePoint Designer workflows) or a SharePoint event receiver.
In this post, I’m going to use a SharePoint Designer workflow, just for demonstration purposes.
Where uploading images from InfoPath to SharePoint is concerned, you’ve got 2 options for controls:
- If the InfoPath form is going to be filled out using the InfoPath client application, you can use a normal Picture Box control to upload images.
- If the InfoPath form is going to be filled out through a browser, your only option is to use a File Attachment control to upload images, because the Picture Box is not supported in browser forms.
Here I’ll be creating an InfoPath browser form to upload images, so will use a File Attachment control. One thing to note about this control is that you cannot limit the allowable file types on it if you place it on an InfoPath browser form, so you’ll have to write code to restrict the file type to an image file type.
The code that I’ve written for this solution does not differ much from the code I wrote for a previous solution that also used a custom SharePoint Designer activity. The only difference is that I’ll be looping through file attachments stored in a Repeating Table on an InfoPath form in the custom workflow activity.
I’ve created 2 video tutorials – actually it was one, but I had to split it up, because it was too long – which demonstrate the code and technique used for this solution. Creating custom SharePoint Designer activities can be daunting at first, but once you know and perform the steps to create your first, subsequent ones will become easier to create. Hopefully these 2 video tutorials will get you to that point:
- Part 1: Upload images from InfoPath to a SharePoint Picture Library using a custom SPD action
- Part 2: Upload images from InfoPath to a SharePoint Picture Library using a custom SPD action
Recipe 98 of InfoPath 2010 Cookbook 3 (for C#) and InfoPath 2010 Cookbook 4 (for VB) teaches you how to upload a file that is stored in a file attachment control or an image that is stored in a picture control on an InfoPath form to a SharePoint document library or to a SharePoint picture library. These two solutions are much easier to create than a custom SharePoint Designer workflow activity, they do NOT make use of workflows, and they do not require Full Trust to run.
Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.