Skip to main content

Notifications

Community site session details
Power Automate - Building Flows
Answered

MS Forms upload file, change file name in OneDrive, email file with changed name via Power Automate

Like (0) ShareShare
ReportReport
Posted on 5 Jul 2022 20:12:39 by

I'm currently in the processing of brainstorming a flow that seeks to take a user's file, upload the file to our agency one drive, rename that file after the upload, and then receive a copy of that renamed file in their email.

 

I'm having a terribly difficult time getting myself along from here: the uploaded document hits my OneDrive, I need to rename the file, then I need to send an email to the author of the Forms response with the renamed-uploaded file as an attachment.

 

I'm stumbling when it comes time to modify the uploaded file's name and location in OneDrive, subsequently I'm not able to figure out how to attach this renamed file yet.

 

Help?

  • Verified answer
    Community Power Platform Member Profile Picture
    on 06 Jul 2022 at 17:52:52
    Re: MS Forms upload file, change file name in OneDrive, email file with changed name via Power Automate

    UPDATE: I figured it out.

     

    This may not be the most elegant solution but I learned a whole bunch along the way. If I'm wrong or explain something poorly, please point out the mistakes and, if you can, provide the correct information where possible.

     

    To get this Flow to work you're gonna need a little prep. You'll need at minimum the following three variables: LocalFileID, NewFileName, and NewFileBody, they're pretty obvious what they're intended to be but for absolute clarity here's mine:

    LocalFileID.PNG

    "Gimme file upload" is the title of my file-upload question on my Form. In your Flow, this will be the output containing the uploaded file reference.

     

    Next we're going to pull apart the properties of the file-upload output using a Parse JSON:

     

    {
        "type": "array",
        "items": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "link": {
                    "type": "string"
                },
                "id": {
                    "type": "string"
                },
                "type": {},
                "size": {
                    "type": "integer"
                },
                "referenceId": {
                    "type": "string"
                },
                "driveId": {
                    "type": "string"
                },
                "status": {
                    "type": "integer"
                },
                "uploadSessionUrl": {}
            },
            "required": [
                "name",
                "link",
                "id",
                "type",
                "size",
                "referenceId",
                "driveId",
                "status",
                "uploadSessionUrl"
            ]
        }
    }
    Huge thanks to Chad Kealey, YT.
     
    Your Parse JSON Flow action should look like this next:
    ParseJSON.PNG
    Where, "LocalFileInfo" is your variable created out of the Forms File-upload output.
     
    Next we're going to build our "NewFileName" variable, it should look like a basic string variable. This will become the file name without extension, so keep that in mind later in your development. Enter whatever name you want, but remember that this information will be transmitted via the internet, refrain from using special characters like: !@#$%^&*(), treat it like a normal file name on your computer.
     
    Here's mine for example:
    NewFileName.PNG
    I'm using the responses from my Forms user to build a new file name in my OneDrive. If you have no need to rename the file, you can skip this step.
     
    Next we need to build our "NewFileBody" variable, pretty simple too.
     
    Create  a basic String type variable and give it the Body property of your Parse JSON Flow action.
     
    Here's mine:
    NewFileBody.PNG
     
    Finally we're ready to begin doing something to all this data.
     
    Compose a Rename or move a file (OneDrive) Flow Action. It will probably be converted into a For-Each sub-action, that's fine. This is because of the nature of File-Upload outputs being an array type object. Since there can be multiple files uploaded at a time, even if we're only dealing with one, the rest of the Microsoft systems must also handle for this situation. Keep this in mind!: If you only have one uploaded file we're dealing with, it's still treated as an array!
     
    My rename/move action is simply called, "Rename a file". Keep in mind you can do both a rename AND a move file action in the same Flow action block. To rename a file, add the desired file name at the end of your file path: /Apps/Microsoft Forms/TEST/Unga.Bunga.png (< this is your new file name), if you want to change the directory then simply add or remove to the file path like so:
    /Apps/Microsoft Forms/Unga.Bunga.png (or) /Apps/Microsoft/Forms/TEST/Subliminal Testing/Super Subliminal Testing/Unga.Bunga.png
     
    Here's my Rename a File for-each:
    RenameFile.PNG
     
    Next we need to get a good reference to the file content (in human-speak, get to the file itself), and a good reference to the file name. We already have the file name (if you're changing it) as a variable. All we need to do is find the file in our OneDrive and that'll be enough to get a reference to the file content.
     
    Create a "Find files in folder" OneDrive Flow action. In the "Search query" box enter your file name and the extension. It's important that you add the extension because otherwise OneDrive is being instructed to search for an unrecognized file. (Or the wrong file)
     
    For example, you might have the file "Unga.Bunga.png" in your OneDrive, but also you have "Unga.Bunga" (without file extension). If you were to simply enter the Search query of "Unga.Bunga" you'd always get the one without an extension, or worse, no file at all and a Flow error.
     
    Here's an example of my Find files in folder Flow action:
    Find Files.PNG
     
    Almost done now. We've got a way to get a good reference to the file in our OneDrive now. Previously we just had a reference from Forms about the file.
     
    Now we have to create a Get file content using path Flow action. Provide this action the full file path to your uploaded file, plus the name and extension of the file. Format your file path like this:
     
    /Apps/Microsoft Forms/Your Form Name/Your Upload Question/YourFileName.extension
     
    Use a forward slash between the directory where the file exists and the file name, just like on your computer.
     
    Here's mine:
    GetFilePath.PNG
     
    Finally, we're ready to email this file back to the author and or whomever.
     
    Create a Send an Email (v2) Flow action. Set the To: field to whomever you need this email to go to. Set up your subject, body, and any other properties you need to set up. When you're all done and the email is dressed up and ready to go, you can now add the references to the attachment file you want.
     
    To do so, click on "Show advanced options". In the "Attachments Name - 1" field, enter the variable for your new file name followed by the extension. In the "Attachments Content - " field, enter the "File content" variable from the "Get file content" subsection in the "Add dynamic content" menu.
     
    If you have the need to add more than one attachment you can simply repeat the above three final steps until the desired goal is met by containing Find files in folder, Get file content using path, and Send an email in a for-each loop triggered by the length of the Body property of the Parse JSON action. I'm not entirely certain about the validity of that advice however, as I have no need to do that. I also haven't tested it. LOL.
     
    Here's one last example of my email with my single attachment from my Forms response, renamed toboot:
    UploadedFileAttachment.PNG
     
     
    I struggled really hard for a hot minute to get this working. I've been off-and-on developing this solution for a little over 6 months at the time of writing this. I cannot thank Chad Kealey enough for creating his tutorial video on YouTube and for being so informative.
     
    I also want to extend a thank you to everyone on the Microsoft Power Automate Community forum for being supportive of each other and for always providing as much information as humanly possible. Without the collaborative environment of this forum, and people like Chad, I'd likely never have figured out this solution.
     
    I hope this benefits anyone who was stuck in a similar situation as me.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard
Loading started
Loading started
Loading complete