Automating file management is an excellent way to save time, especially if you have many. There are many advantages to knowing when a file is created, and 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” which 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:
Power Automate tends to save the most common triggers on the main screen, so check there before going through the full hierarchy. Also, you can use the search to find it quickly.
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 you want to search.
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 many more folders to choose from. In addition, you can pick other “Document Library”:
For example, you can also pick the “Site Pages” to check if a new page has been created. The“Site Assets” is used to store all the content and files necessary for a SharePoint site to function correctly, like Logos, and OneNote notebook, to name a few, and 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>"
}
}
So that you know, 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 getting the ID by encoding the special characters is possible, 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 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 opening the action and checking the details.
Always add a comment.
Adding a comment will also help to avoid mistakes. Indicate your expectations, 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.
Back to the Power Automate Trigger Reference.
Photo by Timon Studler on Unsplash
Hi Manuel, good info about the trigger.
Do you know of a simple way to trigger on file creation in any subfolder, without the need to specify names of subfolders?
So if I monitor \documents that it triggers on file creation in \documents\1234, \documents\87126 etc.
Thanks!
Hi Johannes,
Yes, it’s possible but for the whole library. You can use the “When a file is created (properties only) trigger”.
You can use it without a defined path, and it will trigger all files. So if you don’t have a dynamic library, it could be good to use it.
To get only the subfolders, you can use the contains function with something g like “/folder_1/folder_2/” so that you know what you will catch everything under folder_2.
Would this be possible?
Thanks!
Thank you for your quick and helpful answer, Manuel!
I don’t know the exact structure of the system I will need this for yet, but I feel confident to be able to solve the task with your information.
Thanks!
Sounds amazing! If you need any more help please let me know and I’ll help in any way I can.
Hi Manual, is there a way to get the link in an email notification when you have a new file added to a folder or library?
Hi Dave,
Sure it’s possible. Just follow this trigger with a “Create share link” and then use that link in a “Send email notification action” for example.
Cheers
Manuel
Hi Manuel,
Could you advise any workaround for limitation of this trigger you mentioned?
I need a simple one to fire the flow when file is Added (Moved from other folder) to the sub-folder.
I will appreciate any suggestion.
HI KoYoT,
Not that I’m aware of, but if I find something or someone else knows of one, I’ll post it here.
Sorry 🙁
I need to trigger the flow when an new file is created in site. Not for any specific list or library. Is it possible to do that?
The broader that you can go is with the “When a File is created (properties only) trigger”. It checks for sub-folders, but it’s always limited to a document library.
For a whole site is tricky, but if you don’t have a lot of document libraries, this could be a solution for you, but you would always have to duplicate it depending on the number of libraries you have.
I am looking for a trigger to go off only when a file has been added that is also appoved.
Currently on our intranet all files that are added get mailed but this means also concepts and files that are still in the approval process.
My Power Automate Account is showing the trigger you linked above as Deprecated, meaning they are sunsetting it and we will lose that functionality. Any other workarounds for receiving notification from SharePoint Libraries?
You can use the “When a file is created or modified (properties only) Trigger” and configure a folder to look at changes.
Hi Manuel
Unfortunately this trigger (When a file is created (properties only)) fires for files of subfolders as well. Is there any known workaround for this?
In my case, I want to get notified if the file uploaded in “Mainfolder” already exists in “Subfolder”. This part works fine. The problem is, when a file is uploaded in “Subfolder”, the flow fires and notifies me that the file already exists…
Regards
Ignore my last comment, I just found out that I can check the folder path. My bad.
Exactly! Good job!!!