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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Saving and renaming em...
Power Automate
Answered

Saving and renaming email attachment to SharePoint

(0) ShareShare
ReportReport
Posted on by 7

Hi, I am trying to get an email attachment from Outlook, add the current month and year to the file name and save the file in a SharePoint location.

 

The problem I am getting is that once I have the file when I try to open it I get an error message - 

"Excel cannot open the file "FileName.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file"

 

I suspect that the problem is coming from the way I try to get the file extension by using a Compose action and the following expression -

last(split(variables('AttachedFile-Name'), '.'))
 
mtomova_0-1691263674270.png

 

mtomova_1-1691263712920.png
 
mtomova_2-1691263775560.png

 

Categories:
I have the same question (0)
  • Verified answer
    trice602 Profile Picture
    16,164 Super User 2026 Season 1 on at

    Hi @mtomova ,

     

    Here's one way to do it, please mark as a solution if this was helpful!  I did a test with a jpg and an excel file. Always glad to help! Tom

     

    I create four variables (code below).  Also to help expand your knowledge of Power Automate, the last two variable expressions were created with Format data by Examples - this can really help you work through expression challenges and I provided the example for the AName at the very end.

     

    1) Month (we want 08)

    2) Year (we want 2023)

    3) AName (we want the file name without the extension)

    4) AType (we want the extension)

     

    trice602_0-1691286689209.png

     

    trice602_1-1691286770209.png

    trice602_2-1691286811391.png

    trice602_3-1691286835691.png

     

    split(outputs('Get_Attachment_(V2)')?['body/name'], '.')[0]
     

    trice602_4-1691286897736.png

     

    slice(outputs('Get_Attachment_(V2)')?['body/name'], indexOf(outputs('Get_Attachment_(V2)')?['body/name'], '.'))
     

    trice602_5-1691286972315.png

    trice602_6-1691287036495.png

     

    Example of Format data by Example for AName (how to get the attachment name without the extension)

     

    trice602_7-1691287414290.png

     

  • mtomova Profile Picture
    7 on at

    Hi, thank you so much. It worked exactly as expected!

  • trice602 Profile Picture
    16,164 Super User 2026 Season 1 on at

    Nice @mtomova !  I love it!  I have found that in many cases the format data by example can be very helpful!  Feel free to tag me in your future posts!  If I can contribute to an answer, I will be glad to participate.  Always glad to help! Tom

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 641

#2
Vish WR Profile Picture

Vish WR 640

#3
Haque Profile Picture

Haque 495

Last 30 days Overall leaderboard