web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : fXWmYP1tmOc3V+I9z2Dun3
Power Automate - Building Flows
Answered

Changing a file´s name to attach it to an email without changing the name in Sharepoint

Like (0) ShareShare
ReportReport
Posted on 31 Oct 2023 18:17:18 by 2

Hello. I have a flow in which users load information with a MS Forms, it then drops into an array of folders in SharePoint, and what I want to do is attach them in an e mail that will be sent to a bot that analyses its contents. The problem is that the bot requires the files to be named in a specific way, and MS Forms adds the tag of the user into the name of the file, so I tried changing the names of the files directly on SharePoint, but since they are all now named the same the flow does not attach the correct information. So, is there a way to use the user tag to pull the documents and before attaching them to the email changing their names without altering the files in Sharepoint?

I have the same question (0)
  • Verified answer
    ManishSolanki Profile Picture
    15,089 Super User 2025 Season 2 on 01 Nov 2023 at 04:14:27
    Re: Changing a file´s name to attach it to an email without changing the name in Sharepoint

    Hi @pepeHR 

     

    You could refer the below sample for pulling the files from the folder and rename the file name when storing the file details in a variable. Finally, we will pass the variable in the attachment parameter of send an email action.

     

    1. Firstly, initialize a variable 'emailAttachments' of type array that will hold the file details (file name & content bytes):

    ManishSolanki_0-1698810939327.png

     

    2. Next, add Get files action to get the files from the folder. 

    ManishSolanki_1-1698811025865.png

    You may change the parameter as per your need. here, I have also used filter query to limit the search to files:

    FSObjType eq 0

     

    3. Add "Apply to each" action & pass the value output from Get files action. Inside the block, add "Get file content" & pass identifier from the get files action:

    ManishSolanki_2-1698811356041.png

    Continue inside "Apply to each" action block, add "Append to array variable" action to add each file information in the variable:

    ManishSolanki_3-1698811539898.png

    The json used in "Value" parameter:

    {
    "name":@{concat('customname','.',last(split(item()?['{FilenameWithExtension}'],'.')))},
    "contentBytes":@{body('Get_file_content')}
    }

    In the above json, name stores the file name, so you may modify it as per your need. This name will be used name of the attachment in the email.

     

    4. Now, add "Send an email" action and click the button as highlighted in the below screenshot:

    ManishSolanki_4-1698811862021.png

    Pls note that this action should be added after the apply to each action, not inside the apply to each block.

     

    Now, set the variable in the "Attachments" parameter as shown below:

    ManishSolanki_5-1698811998128.png

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 725 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 363 Moderator

#3
Power Apps 1919 Profile Picture

Power Apps 1919 341

Last 30 days Overall leaderboard
Loading complete