cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft Flow - How to check if a file exists in SharePoint

I will start by describing my flow a bit. 

 

In my flow I've got 2 document libraries. When a document is created in the first document library I want to copy the document to a second library and I'm doing this by using the Create file action. So my flow looks something like this:

 

CreateFile.PNG

 

But then I noticed in my flow history that every now and then I would get a create file going into retry mode as it was marked with the amber tick. 

 

 

OopsFLow.jpg

This was happening as users were making multiple updates to the same document very quickly after eachother. One of my flow instances would actually trigger and the second flow would go into this retry state. 

 

So then I decided to add a 'does file exist' check. Unfortunately this action doesn't exist. But there is a great workaround available.

 

Before I run the create file action, In now added a get file content using path action followed by a scope that includes all the actions that I want to run after I create a new file.

 

 

Workaround.PNG

 

To make this all work I set the scope's run after settings to 

 

 FailedRunafter.PNG

 

And now my check if file exist in my flow is complete. 

Comments

Thank you for sharing the Microsoft Flow tips

Thank you for posting this, I am in similar shoes, and was thinking of how to use REST to probe for filename existence but this technique seems faster. I will give this method a try.

The problem with your workaround is that flow still fails when Get content using path fails. Of course this activiity is logged.

 

One problem with your post is that we don't see the whole flow. It looks like you might have 2 conditions.

 

I recently found a solution for checking to see if a list item exists that proved quite helpful. Basically you use Get Items with OData filters and then a custom condition to evaluate the response code. It's nice and tidy - none of the actions fail whether the item is there or not. I tested it out, and it works great.

 

I'm not positive if this method could be adapted to probe for documents succesfully, but it might be worth a shot.

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor