How to Create File Using Power Automate? [SharePoint & OneDrive]

Last week, I was working on a Power Automate flow and received a requirement to create a file in a SharePoint library whenever a new email with an attachment arrives. The client wanted to automate the process so that when an email containing an attachment is received, the attachment is automatically saved as a file in a specific SharePoint folder.

In this tutorial, I will explain how to use the Create File action in Power Automate. Additionally, I will cover:

  • How to create file using Power Automate
  • How to create an Excel file in SharePoint using Power Automate
  • How to create a file in OneDrive using Power Automate

Create File Action in Power Automate

The Create File action in Power Automate creates a new file in a specified location, like OneDrive or SharePoint. You provide details like the file’s name, the folder where it should be saved, and its content (text, data, or an attachment). When the flow runs, this action generates the file in the selected folder with the specified content.

The Power Automate Create File action for SharePoint accepts four parameters.

  • Site Address
  • Folder path
  • File name
  • File content
create file power automate

The Power Automate for Create File action for Onedrive business accepts 3 parameters:

  • Folder path
  • File name
  • File content
create file in power automate

Create File Using Power Automate

For this example, I created a SharePoint document library named HR Documents.

power automate create file

Now follow the below steps:

1. Create an automated cloud flow. Give the flow name and select the trigger When a new email arrives (V3).

create file action in power automate

2. Next, we will add get the attachments action from Outlook with the message ID and attachment ID that will automatically add the Apply to each action.

create file sharepoint power automate

3. Select Create file action for SharePoint. Then, provide the Site address, Folder path, Filename, and File content from the dynamic content.

power automate create file file content

Now click on Save, and to run the flow, send an email attachment to the Outlook inbox.

power automate create file in sharepoint

Now, you can see in your document library that a new file has been created from the attachment.

power automate create file content

You can create a file from an attachment using Power Automate.

Create an Excel File in SharePoint Using Power Automate

Before I explain how to create an Excel file using Power Automate, you need to create an Excel file in a document library. I have already created one.

create file power automate file content

Now follow the below steps:

1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

power automate create file folder path

2. Now choose a Get file content action for SharePoint Connector and configure the required parameters:

  • Site Address: Select the SharePoint site address from the dropdown where we create the blank Excel file.
  • File Identifier: Choose the Excel file we created before.
power automate create a file

3. Now, add an action to create Excel files in a SharePoint library. Click the + icon to add the Create file action (under the SharePoint connector) and provide the required parameters:

  • Site Address: Select the SharePoint site address from the dropdown menu where you store all your Excel files.
  • Folder Path: Select the folder path.
  • File Name: Provide the Excel file name with the .xlsx extension.
  • File Content: Use the dynamic content File Content from the Get file content action.
sharepoint create file power automate

Now, click Save and run the flow manually after it runs successfully. You will see an Excel file created in the SharePoint document library.

powerautomate create file

Create File in OneDrive Using Power Automate

In this example, I will show you how to store an attachment in OneDrive when a new item is added to a SharePoint list; you can create a Power Automate flow that extracts the attachment from the new item and saves it into a specific folder in OneDrive.

For this example, I created a SharePoint list with the following columns and data types:

power automate create sharepoint file

Now follow the below steps:

1. Create an automated cloud flow. Give the flow name and select the trigger When an item is created. Also, provide the Site Address and List Name.

power automate create file action

2. Next, we will add the get attachments action from SharePoint and provide the below parameter:

  • Site Address: Select a specific SharePoint site from drop-down.
  • List Name: Choose a particular list.
  • Id: Select Id from dynamic content under When an item is created.
create file file content power automate

3. After that, take the Get attachment content action to retrieve the details from the attachment. Then, Provide the below parameters:

  • Site Address: Select a specific SharePoint site from drop-down.
  • List Name: Choose a particular list.
  • Id: Select Id from dynamic content under When an item is created.
  • File Identifier: Take Id from the dynamic content of Get attachments.

You can see that a For each loop will be added automatically, taking Body outputs from Get attachments.

power automate create file onedrive

4. Next, add the create file action from onedrive and provide the below parameters:

  • Folder Path: Select the folder path in OneDrive where the attachments should be saved
  • File Name: Use the Display Name from the Get attachments action to maintain the original file name.
  • File Content: Use the Attachment Content from the Get attachment content action.
power automate onedrive create file

Now click on Save and run the Flow manually. Then, add an item with an attachment to the SharePoint list.

create file onedrive power automate

After the flow runs successfully, go to the Ondrive, and you will see that the file has been created.

power automate sharepoint create file

In this article, I covered how to use the “Create File” action in Power Automate to automate file creation in SharePoint and OneDrive. I explained how to set up a flow that automatically saves email attachments to a SharePoint library.

Additionally, I covered how to create Excel files in SharePoint using Power Automate and store attachments in OneDrive when new items are added to a SharePoint list.

Related Power Automate articles:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…