Save Attachments from Existing SharePoint List to Document Library and Create Individual folders

Australia 1 Reputation point
2020-10-20T07:26:54.897+00:00

Hi @Echo Du_MSFT and fellow Power Automate veterans,

I have been trying to follow this post and so far I've been really enjoying the learning process:

https://learn.microsoft.com/en-us/answers/questions/82189/copy-attachments-from-existing-sharepoint-list-to.html

The post teaches us how to save attachments to one Document Library but is it possible also to save them to individual folders?

My scenarios is that a user attaches new files to the list against
item 1 'Case 1 John Smith - 20.10.2020'
item 2 'Case 2 Amy Citizen - 31.10.2020'

I would like the attachments to be automatically saved in Document Library in the following convention:

Document Library > Folder (Case 1 John Smith - 20.10.2020) > Attachments x, y, z

Document Library > Folder (Case 2 Amy Citizen - 31.10.2020) > Attachments x1, y1,

And hope that the flow is smart enough to

  1. skip creating a folder if the same folder name already exists and
  2. save the new attachments and not overwrite existing attachments that are already in the folders?

Thank you.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,810 questions
{count} votes

2 answers

Sort by: Most helpful
  1. JoyZ 18,071 Reputation points
    2020-10-21T04:43:30.293+00:00

    Hi @Australia ,

    The Flow will trigger when an item is created in a particular list.

    The first action would be get the attachments from a particular item submitted.

    33865-image.png

    Next, we get file contents using the file identifier "id" which obtained from ‘Get attachments’ action.

    33856-image.png

    Meanwhile, use the Compose action to create a relative path using Title from the item created action.
    (In this case the title value looks like this: Case 1 John Smith - 20.10.2020, this will also skip creating a folder if the same folder name already exists)

    33913-image.png

    Lastly, create the files in the particular folder created above, If the name of the new attachment is the same as a file name in the current folder, the error "A file with the name xxx already exists" will occur, in order to avoid the error, using the unique item id --- Attachments Display name as the new file name:

    33908-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

  2. Australia 1 Reputation point
    2020-10-21T11:28:35.313+00:00

    @JulieWang-MSFT ,
    Thanks for the reply again. I noticed the flow can now be triggered when I attach an attachment, using "when an item is created or modified". However, it does not seem to produce the desired output.

    What we wanted to see is:
    Document Library/Case 1 John Smith - 20.10.2020/> attachments x.pdf, y.pdf, z.pdf
    (where z.pdf is the only new attachment, the other two are existing attachments)

    However in reality, the flow produces:
    Document Library / x.pdf (folder name) / x.pdf,
    Document Library / y.pdf (folder name) / y.pdf,
    Document Library / z.pdf (folder name) / z.pdf


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.