Creating files automatically is a godsend since there are a lot of actions that we can do. For example, I create a new folder per article I want to write and automatically create the template files I need. It’s a simple operation but having a folder waiting for you is a productivity boost. So today, let’s look at OneDrive’s “create file” action and how it can help us.
Where to find it?
You can find it under “Standard”.
You may need to expand.
Pick “OneDrive for Business”.
Pick the “create file” action.
Here’s what it looks like.
Power Automate tends to save the most common actions in the main screen, so check there before going through the full hierarchy. Also, you can use the search to find it quickly.
Now that we know how to find it let’s understand how to use it.
It’s pretty simple to use since we need to provide the location to save the file, the name we should call it, and the file’s contents.
You can pick the location in the UI or provide the path:
Be careful while providing the path since OneDrive for Business doesn’t like special characters and has special rules on how to parse them. I recommend that you can pick the value from the UI, and then you’re safe from any issues with the path. Don’t forget that you should provide the folder where to save the file, but don’t include the file’s name. This will be defined in the next correctly. This is a common mistake, especially if you build the path in previous actions in your Flow.
As mentioned before, the file name should not be in the path. You can define it in the “File Name” field, and please don’t forget the file’s extension; otherwise, it will be considered corrupted.
Please keep the files with as least special characters as possible. OneDrive for Business doesn’t like them, and some will be converted automatically to underscores. Power Automate indicates that it will convert them automatically. Still, I had cases in the past of Flows that failed due to special characters, so do your “homework” before and “clean” the file name as much as possible.
The file content creates confusion for many people since it can be text, but it can also be a base64 representation. It all depends on the type of file that you are creating. For example, if you’re creating an Excel file, I recommend providing the value you get from other actions like the “￼Get File Content￼” action. These actions take care of all necessary encodings and ensure that the file is created with the correct format. If you want to create a text file, for example, the file will be created when you can provide the text values directly in the field. For example:
Be sure to test the file after you create it, especially if you create it dynamically, so you’re sure it was not corrupted in the process.
Finally, you can get the “File Content” from any action in Power Automate as long as it contains the correct file structure. For example, you can use SharePoint’s analogous “Get file content” action to get a file and then use the “File Content” to create a file in OneDrive for Business.
As mentioned before, we cannot use some special characters for the file’s name, and they will be converted to underscores.
Here are some things to keep in mind.
Name it correctly
The name is super important in this case since we’re creating the file by calculating the path or having a defined static one. Always build the name so that other people can understand what you are using without the need to open the action and check the details.
Always add a comment
Adding a comment will also help avoid mistakes. Indicate where the path comes from, for example, if it’s calculated and how. Also, indicate any rules to define the file’s name in case you do it dynamically as well as the source of the file’s contents. This information can be a few actions before, and explaining it in the action will help enable faster debugging when something goes wrong.
Always deal with errors
Have your Flow fail graciously and notify someone that something failed. It’s horrible to have failing Flows in Power Automate since they may go unlooked-for a while or generate even worse errors. I have a template that you can use to help you make your Flow resistant to issues. You can check all details here.
Back to the Power Automate Action Reference.
Photo by Kelly Sikkema on Unsplash