How To: Get Attachment URLs from a list item

This blog post comes out of a question I was recently asked by our amazing support team.

A company maintains a SharePoint list for job applications. The list not only stores job applications but also attachments that were submitted alongside the job application. Now they need to extract the URL for each attachment that accompanies a list item (aka job application) to be able to include a direct link to the attachment within an email.

How does it work?
Let us have a look at the workflow within the UDA, which is quite simple.

We are using a web service, which comes out of the box with SharePoint. The Lists (http://[SITEURL]/_vti_bin/lists.asmx) web service. It lets us interact with lists anywhere in our SharePoint environment. The web method we are interested in is the GetAttachmentCollection one. It returns all attachments assigned to a list item as part of an XML. 

Within the UDA we call the Lists web service first and get all attachments as part of an XML. In case there was an error, the UDA records the error occurrence and spits out an error message, which you can handle appropriately within your workflow. The same for the Query XML action. The next step is to extract all attachment URLs using the Query XML action. The individual results are stored in a collection, which is then returned as part of the UDA.

That’s it. Simple, isn’t it? And all that with no code and just using web services which SharePoint already provides.

How do I use the UDA?
Drop the UDA into your workflow where required. The UDA requires a few input parameters: 

  • Item ID – the ID of the item we want to get the attachments from
  • List Name – the name of the list containing the item
  • Site URL – the URL of the site the list sits in. This is required to make the UDA work with ANY list in your environment.

In the event of an error within the UDA (connection issues, etc.) there are 2 output parameters: 

  • Error Message – The message returned by the web service that errored
  • Error Occurrence – Indicates that an error occurred within the UDA

Using the output parameters will help you to handle the exception appropriately within your workflow.

Last but not least, the UDA contains the important output parameter “Attachments URLs” which contains the collection of all attachment URLs for the specified item.

The following is an example configuration of the UDA.

The web service in the UDA uses a workflow constant (Site Collection Level) called “SharePoint Web Service Account” of the type credential. You will have to create this constant before you can use the UDA as it currently stands. The account will have to be able to read web services across the site collection, so read only access to all sites for this account will be fine.


Extract Attachment URLs – UDA and NWF files

Tags: , , ,

No comments yet.

Leave a Reply