December 20, 2024

Power Automate: OneDrive for Business – Get File Content Using Path Action

I’ve already covered the “Get File Content” action in a previous post, but today I would like to focus on the “sister” action called “Get file content using the path.” They look the same, but they are quite different, even if the end objective is to get the contents of a file.

It does exactly as advertised. You define a file, and the action fetches the file’s content and returns it to you. The difference between this one and the Get File Content action is that you provide the ID to the file, while in this one, you provide the path. There are advantages and disadvantages so let’s explore them.

Where to find it?

I’ll show you where to find it in both OneDrive and OneDrive for Business, but after this, I’ll use the OneDrive for Business as examples.

OneDrive

To get it for your OneDrive:

You need to expand and search for “OneDrive.” Or you can search for it in the search bar, but be careful not to select “OneDrive for Business.”

Select “Get file content using the path”:

This is what it looks like:

OneDrive for Business

To get it for your OneDrive for business, it’s displayed in the preview, but if you can’t find it for some reason, expand and search for it.

Select “Get file content using the path”:

Looks the same as before.

Pro Tip:
Power Automate tends to save the most common actions on the main screen, so check there before going through the full hierarchy. Also, you can use the search to find it quickly.

Usage

You can use it in 2 ways:

  1. Select the file by selecting the folder icon and going through your folders until you find the file you want.
  1. Build the path dynamically and add it to the “File” field:

Let’s look at the first case:

Looks good. Let’s copy and paste the path and see what we get:

Looks awesome also. I chose this example for a reason. I decided to do the same example as in the Get File Content action to see the difference. You can build the path yourself and provide it to the “Get file content using path” action, and all will work out, unlike the Get File Content action.

Where to use one over the other?

So the important question is, where should I use the Get File Content action and the Get file content using path action?

It’s better to use the Get File Content action you know the file ID. You can provide the ID from other actions, but you need to have it from somewhere else without changes or parse from your side. Don’t try to “calculate” it; otherwise, you’ll have Flows that will fail. Having the ID is as “fail-proof” as it gets since you’re accessing the file, but IDs may change in the future behind the scenes, so be aware of this.

Another advantage is if you have a file that may change from a folder to another. Using the ID, you’ll always get the file, regardless of where it is, and that’s a huge advantage. But, again, don’t trust that the ID will be the same when the file is moved, so don’t store it to reference later. It won’t guarantee that you always get the file even if it’s moved.

On the other hand, it’s better to use the Get file content using path action when calculating the path but don’t know the ID. For example, you can have a defined folder and file structure, so it’s simple to determine where the file is and how it’s called. You don’t have the file ID, but you can still access the file without the need to get the folder contents, find your file, and then get the ID. Much faster, but you need to be extra careful when it comes to error handling.

Limitations

You can’t access files in a shared library. You can find here a workaround from the Power Automate Community.

Recommendations

Here are some things to keep in mind.

Name it correctly

The name is super important in this case since we’re getting the file by either calculating the path or having a defined static one. Always build the name so that other people can understand what you are using without opening the action and checking the details.

Always add a comment.

Adding a comment will also help to avoid mistakes. Indicate where the path comes from, for example, if it’s calculated and how. It’s important to enable faster debugging when something goes wrong.

Always deal with errors.

Files may change places and names, so what’s true now is not a few weeks from now. Have your Flow fail graciously when the file doesn’t exist and notify someone that the file is missing. It’s horrible to have failing Flows in Power Automate since they may go unlooked for a while or generate even worse errors.

Am I missing something? Leave a comment or interact on Twitter. Let’s work together to make this reference as complete as we can

Back to the Power Automate Action Reference.

Photo by Lili Popper on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon