cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KirstyClark
Level: Powered On

Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Hi all, 

 

I currently receive excel files from users via an email to MS Teams. When an email is received, a copy of that email is saved to a specified folder. Any attachments (ie. the excel file) is also saved separately into the folder. 

I'd like to create a flow that does the following:

  • Trigger - New File Created in Sharepoint Folder
  • Condition 
    • If not excel file
      • Action - Delete
    • If excel file
      • Action - copy to new folder
      • Action - delete original

The main issue I have is that no matter what I select in the condition after the Trigger of file creation, I cannot seem to get a "True" result for the file being excel related. Any advice would be greatly appreciated.

KC

 

MS FLow Issue.png

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Hi @KirstyClark,

 

I have made a test and the issue is confirmed on my side. I think your thought is correct, there is something wrong with the "When a file is created in a folder" trigger.

 

Actually, the File name dynamic content the "When a file is created in a folder" trigger returned is the base64-encoded representation of the File Name.

 

As an alternative solution, please take a try with the following workaround:

  • Add a "When a file is created (properties only)" trigger, specify Site Address and Library Name.
  • Add a condition, click "Edit in advanced mode", type the following formula:
@or(contains(triggerBody()?['{FilenameWithExtension}'], '.xlsx'),contains(triggerBody()?['{FilenameWithExtension}'], '.xls'))
  • Within "If/yes" branch of Condition, add a "Get file content" action, specify Site Address, File Identifier field set to Identifier dynamic content of the trigger.

         Add a "Create file" action, specify Site Address, Folder Path field set to new folder. File Name field set to File name with extension dynamic content of the trigger, File Content field set to File Content dynamic content of the "Get file content" action.

 

         Add a "Delete file" action, specify Site Address, File Identifier field set to Identifier dynamic content of the trigger.

 

  • Within "If/no" branch of Condition, add a "Delete file 2" action, specify Site Address, File Identifier field set to Identifier dynamic content of the trigger.

Image reference:1.JPG

 

2.JPG

The flow works successfully as below:3.JPG

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Can you show the run history output for the flow. You shoudl see the file name there.

KirstyClark
Level: Powered On

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Hi Pieter,

 

Thanks for your response.  I think to your point, the "When a file is created in a folder" step doesn't actually pull a file name. It isn't until I do something with the file (like copy it) that you see the file in the steps. Screen shot below as requested.

 

Hence if I put in a condition to check the filename before the Copy File step, there is no filename to validate and it always fails.


Cheers

KC

 

Microsoft Flow issue 2.png

Community Support Team
Community Support Team

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Hi @KirstyClark,

 

I have made a test and the issue is confirmed on my side. I think your thought is correct, there is something wrong with the "When a file is created in a folder" trigger.

 

Actually, the File name dynamic content the "When a file is created in a folder" trigger returned is the base64-encoded representation of the File Name.

 

As an alternative solution, please take a try with the following workaround:

  • Add a "When a file is created (properties only)" trigger, specify Site Address and Library Name.
  • Add a condition, click "Edit in advanced mode", type the following formula:
@or(contains(triggerBody()?['{FilenameWithExtension}'], '.xlsx'),contains(triggerBody()?['{FilenameWithExtension}'], '.xls'))
  • Within "If/yes" branch of Condition, add a "Get file content" action, specify Site Address, File Identifier field set to Identifier dynamic content of the trigger.

         Add a "Create file" action, specify Site Address, Folder Path field set to new folder. File Name field set to File name with extension dynamic content of the trigger, File Content field set to File Content dynamic content of the "Get file content" action.

 

         Add a "Delete file" action, specify Site Address, File Identifier field set to Identifier dynamic content of the trigger.

 

  • Within "If/no" branch of Condition, add a "Delete file 2" action, specify Site Address, File Identifier field set to Identifier dynamic content of the trigger.

Image reference:1.JPG

 

2.JPG

The flow works successfully as below:3.JPG

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Administrator
Administrator

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Hello, @KirstyClark!

 

Have you had a chance to apply @v-xida-msft‘s recommendation to adapt your Flow? If yes, and you find that solution to be satisfactory, please go ahead and click “Accept as Solution” so that this thread will be marked for other users to easily identify!

 

 

Thank you for being an active member of the Flow Community!

 

-Gabriel

Flow Community Manager

-Gabriel
Microsoft Power Automate Community Manager
Are YOU a member of your local Power Automate User Group?
Fill out This Form to claim your Community User Group Member Badge!
KirstyClark
Level: Powered On

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

My initial attempt failed but I will try the proposed solution again this weekend. Apologies for the delay.
KirstyClark
Level: Powered On

Re: Create Flow to Move a File to New Folder in Sharepoint Only If it is an Excel File

Kris, that was perfect! I apologise for my delay in responding but thank you so much for taking the time to respond! 

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons in April

Read the announcement for more information!

firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,553)