SharePoint Attachments

Power Automate: Copy SharePoint List Attachments

Premise

In this post, we’ll discuss how we can automate certain operations around SharePoint List attachments using Microsoft Power Automate. We’ll be discussing the following items: –

Solution

Copy attachments to a document library

Here, the idea is to copy the attachments to a separate document library.

This might be important if, there’s a case scenario of attaching multiple files as attachments. A document library is much more versatile in dealing with files than just plain attachments.

Here’s what we’re going to do. For each list item, we’ll create a new folder in a document library and add all the attachments there.

  • Set the trigger for, When an item is created.
  • Create new Folder. Folder name is a combination of item title and item id so as to generate a unique name. Folder path is set to, concat(triggerBody()?[‘Title’], ‘_’, triggerBody()?[‘ID’])
Power Automate: Create new folder
  • Get all the attachments
Power Automate: Get Attachments
  • For each attachment, download the file content. Input for “Apply to each” is the “Body” from the previous step. ID is the item ID in question. File Identifier is the current attachment’s id.
  • Create a new file in our destination library.

The input can be defined as below,

PropertyAction FromFormula
Folder PathCreate New Folderbody(‘Create_new_folder’)?[‘{FullPath}’]
File NameCurrent Attachment Nameitems(‘Apply_to_each’)?[‘DisplayName’]
File ContentCurrent Attachment File contentbody(‘Get_attachment_content’)
Power Automate: Copy Attachment to Library

Send list attachments as Email attachment

  • I’m keeping the trigger same as, when a new item is created. But, set it as per your requirement.
  • Initialize an empty array variable. This will be used to temporary store all the attachments files.
Power Automate: Array Variable
  • Next, get all the attachments for the current item
Power Automate: Get Attachments
  • For each attachment, download the file content. Input for “Apply to each” is the “Body” from the previous step.
  • Store the file content in our array variable in the following format. Name is the DisplayName from the previous step. ContentBytes is also from the previous step
MS Flow Email Attachment
  • Finally, send the email with the following parameters.
MS Flow Email with Attachment
Power Automate Email Attachments

Delete attachment

There’s an OOTB Flow action card to delete an attachment easily.

Delete Attachment

Key Takeaways

  • Attachment is a key component of a SharePoint list.
  • In this post I’ve demonstrated, some of the key operations that can be done around SharePoint attachments.
  • Using SharePoint files as attachment, we need to ensure the JSON format is in correct format.

Icon made by Pixel perfect from www.flaticon.com

5 thoughts on “Power Automate: Copy SharePoint List Attachments

  1. This is exactly what I needed, a short clear guide to using sharepoint item attachements in Power Automate. Thanks Piyush

    Like

  2. Thank you for this solution!
    Is there a way to copy a file from a document library and attach it to a SharePoint list item as an attachment? – Thanks!

    Like

  3. Hi, I tried your flow and it works fine for every attachment, excepting .msg files, which are saved emails and attached to a SharePoint list. Is it happening just to me or you also?

    Thanks!

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.