• vadim@workflowexcellence.com
  • Utah, United States

Nintex Workflow – Get List Item Attachment in Base64 Custom Action (Happy Thanksgiving)

*** Announcement 7th April 2013 ***

Now available, a Nintex Workflow 2013 of this custom action, that will allow you to get your item attachments into Base64.

This is not backward compatible.  If you’re moving from using this action in 2010 to 2013, I’d recommend you remove that action from the 2010 workflow before exporting the workflow and importing it to your 2013 environment.  Then you can add this action and reconfigure it.  Since it’s only 4 fields, configuring it should take no time. 

ve been hunting around the SharePoint web services, trying to find a web method that will allow me to get the attachments in a list item. The Lists.asmx web service exposes a GetAttachmentCollection web method, but it only returns a collection of Urls that point to the attachments. Unfortunately, I haven’t been able to get the data inside the attachments.

The reason I want the data, is because some web methods such as AddAttachment require a Base64 string to be passed to it.

So I decided to write my own Nintex Workflow Action, based on the information in the Nintex Workflow SDK.

Nintex Workflow SDK

No doubt, someone will send me a message and say “Hey… but you could have done it using this web service.”. Oh well. This is a good learning experience.

If you are interested in the code to read an attachment, have a look at this site :
How to programmatically download attachments from list items in Windows SharePoint Services

Input

We need 3 pieces of information, in order to successfully read an attachment.
1. List name : location of the item that contains the attachment
2. Item ID : List Item ID of the item that contains the attachment
3. Attachment Url : Url to the attached file that we want to read

Output

The only output we want is a Base64 string. If you want to learn more about Base64 click here Base64 on Wikipedia

Action Configuration

Usage

In an example of how you would use this, I created a workflow that obtained the attachment Urls for the list item the workflow is running on, and then extracted the data of each attachment and add it to another list item.

The structure of this workflow is actually quite straightforward, as seen from the completely sequential set of actions.

First we use the Call Web Service action to get the list of Attachment Urls, using the SharePoint Lists web service and specifically the GetAttachmentCollection web method.

We then use the Query XML action, to extract the Urls and store them in a Collection variable. Now that we have each Url in the collection, we use the For Each action to loop through each attachment Url.

Once we have the Url, we use our new action to get the Base64 encoded data of the attachment, and then we use the Web Request action to add a new attachment to another List Item.

The Web Request action is discussed in a previous blog : Nintex Workflow – Web Request action 101

In essence, we are using the Web Request action to call the SharePoint Lists web service, and the AddAttachment web method, which we can’t do with the Call Web Service action.

My initial list item had 3 attachments. 2 Text files and 1 Image (PNG) file. The result after running this workflow, is this list item :

I didn’t go into too much work with creating the filename for the attachments, so they all have a text file extension.

Happy Thanksgiving

I thought given that it’s Thanksgiving in the US (even though I’m an Aussie), I’ll do the giving and you guys can do the thanking 🙂

Below is the link the SharePoint solution that deploys my VT Get List Item Attachment action that I have described in this blog. I don’t recommend you use it a production environment, as I have done limited testing on this action. But it is something you could play with in a Q/A or Development type of environment. I didn’t provide the source code, because it isn’t pretty, and I don’t want to spend too much time cleaning it up. It does what I want it to do, and I’m happy with it.

stallation

To install this solution, run the following command line :
stsadm -o addsolution -filename VTListItemGetAttachmentAction.wsp

You can then go into SharePoint Central Administration->Operations and click on Solution Management. Here you can deploy the solution.

This deploys into the following folder :
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\NINTEXWORKFLOW\VadimsActions\VTListItemGetAttachmentAction

One of the files that gets deployed is the NWA (Nintex Workflow Action) file. You use this to add the action to Nintex Workflow via the NWAdmin.exe utility, located :
c:\Program Files (x86)\Nintex\Nintex Workflow 2007

The command line would be :
NWAdmin -o AddAction -nwaFile VTListItemGetAttachmentAction.nwa

You will probably need to perform an IISRESET, so that the new assembly gets loaded. Then, in Central Administration->Application Management, in the Nintex Workflow Management section click on Manage Allowed Actions. Here you should scroll down to the VT List Item Get Attachment action and enable it.

The action should now appear in the workflow designer.

NOTE : obviously, it’ll be a little different with a 2010 and 2013 environment where you can use PowerShell to add and deploy the solution.

For the 2013, once it’s deployed, activate the VTCustomActions feature for the web applications you want to use this action on. 

Get and Copy Attachment Workflows

Download 2007 Custom Action

Download 2010 Custom Action

Download 2013 Custom Action

Leave a Reply

Your email address will not be published. Required fields are marked *