Automating file management is an excellent way to save a lot of time, especially if you have many of them. There are many advantages to knowing when a file is created, and for that, we have the SharePoint “When a file is created in a folder” trigger. 

To see the SharePoint “When a file is created in a folder” trigger in action, you can go to my cookbook section or check the template “Import a new Excel automatically to a list” that gets an Excel file and imports all its rows to a SharePoint List.

With that out of the way, let’s explore the SharePoint “when a file is created in a folder” trigger a bit more.

Where to find it?

To find it in the SharePoint section.

Select “when a file is created in a folder”. 

Here’s what it looks like:

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

Usage

The SharePoint “when a file is created in a folder” trigger is quite simple. You only need to provide the site address and the folder that you want to search.

Important:
Although you can, please don’t generate the “Folder Id”. It’s always better to define beforehand where you’ll look for files.

Let’s look at the simplest case. Open the picker, and you’ll see the following:

The “Shared Documents” is the default “Document Library” created when the SharePoint Site is created. But as you can see, there are a lot more folders to choose from. In addition, you can pick other “Document Library”:

You can also pick the “Site Pages” to check if a new page is created for example. The“Site Assets” is used to store all the content and files necessary for a SharePoint site to function correctly, like Logos, OneNote notebook, to name a few, can also be used as the source of the trigger. But the most interesting, in my opinion, is the “Lists”. Since your list items can have attachments, you can monitor adding an attachment and parse that file.

Microsoft did a fantastic job hiding the complexity and allowing you to access all the areas with files in the same place.

Outputs

The trigger returns a lot of information in a JSON format, although the conversion from JSON is done automatically for you. Here’s an example:

{
    "statusCode": 200,
    "headers": {
        "Pragma": "no-cache",
        "Transfer-Encoding": "chunked",
        "Retry-After": "0",
        "Vary": "Accept-Encoding",
        "x-ms-file-id": "%252fShared%2bDocuments%252fAttachment%252fExcel%2bTemplate.xlsx",
        "x-ms-file-name": "Excel Template.xlsx",
        "x-ms-file-path": "/Shared Documents/Attachment/Excel Template.xlsx",
        "x-ms-file-name-encoded": "<redacted>",
        "x-ms-file-path-encoded": <redacted>",
        "x-ms-file-etag": "\"<redacted>,1\"",
        "x-ms-request-id": "<redacted>",
        "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
        "X-Content-Type-Options": "nosniff",
        "X-Frame-Options": "DENY",
        "Cache-Control": "no-store, no-cache",
        "Location": "<redacted>",
        "Set-Cookie": "<redacted>",
        "Timing-Allow-Origin": "*",
        "x-ms-apihub-cached-response": "true",
        "Date": "Mon, 20 Sep 2021 16:09:44 GMT",
        "Content-Disposition": "attachment",
        "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "Expires": "-1",
        "Last-Modified": "Mon, 20 Sep 2021 16:09:44 GMT",
        "Content-Length": "17922"
    },
    "body": {
        "$content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "$content": "<redacted>"
    }
}

Please note that we get the file itself in the trigger. This makes it easier since you don’t need to do another action to fetch it. You also have the file Id so that you can change, move or do any other necessary actions.

Limitations

The trigger does not fire if a file is added or updated in a subfolder of the folder that you defined. Also, this only applies to new files. If the file is changed this trigger won’t fire.

Recommendations

Here are some things to keep in mind.

Don’t generate the folder ID

I always recommend against generating the ID. Although it’s possible to get the ID by encoding the special characters, it’s pretty error-prone if you know the path. For example, if Microsoft changes something in Power Automate, you’ll get into trouble, but if you use the IDs from other actions, your Flows become future proof to any changes that may occur.

Name it correctly

The name is super important in this case since we can get the trigger from anywhere and with anything. Always build the word so that other people can understand what you are using without the need to open the action and checking the details.

Always add a comment.

Adding a comment will also help to avoid mistakes. Indicate what you’re expecting, why the Flow should be triggered, and the data used. Also, define why you’re searching in the specified folder. The folder’s name may not be enough to explain what it is and why it’s being used. It’s crucial to enable faster debugging when something goes wrong.

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 Trigger Reference.

Photo by Timon Studler on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: