Power Apps Upload File to SharePoint Document Library

    While working with the SharePoint Online document library, we sometimes need to upload a file or multiple files from Power Apps to the SharePoint document library.

    In this Power Apps tutorial, I will explore in detail information about upload files from Power Apps to the SharePoint document library including:

    • Power Apps upload file to SharePoint document library using flow
    • Power Apps upload multiple files to SharePoint
    • Power Apps upload file to SharePoint document library without flow

    Power Apps Upload File to SharePoint Document Library

    Recently, I got the opportunity to work with Power Apps upload files to the SharePoint document library using different real-time scenarios.

    I have created a SharePoint document library named “Policy Documents,” which has the fields below.

    Column NameData Type
    NameIt is a default single line of text
    ModifiedDate and time
    Modified ByPerson or Group
    Review DateDate and time
    Is ApprovedYes/NO
    powerapps upload file to sharepoint document library

    Now, I would like to upload or add a file from Power Apps to the SharePoint document library. Unfortunately, there is no direct way to upload a file or files to the document library from Power Apps.

    But there is a way to overcome this issue, like connecting the Power Automate Instant flow to the Power Apps and uploading files using a single button click from Power Apps to the SharePoint document library.

    NOTE:

    As of the last update in January 2022, uploading files to a SharePoint document library directly from Power Apps without using Power Automate is not directly supported.
    However, we can directly upload the files from Power Apps to the SharePoint list without using any flows.

    Have a look at the below screenshot for the output.

    power apps upload file to sharepoint document library

    To achieve it, follow the below steps. Such as:

    1. On the Power Apps Screen, insert an Edit form control and set its DataSource to any existing SharePoint list for the “Attachment control.”

    DataSource = 'Company Attachments'

    Where,

    • ‘Company Attachments’ = SharePoint Online list
    powerapps upload multiple files to sharepoint

    2. Now cut the Attachment control, paste it outside the form, and delete the form. You can see some errors will appear in the Attachment control. To resolve those errors, follow the below properties.

    DisplayMode = DisplayMode.Edit
    Items = Blank()
    Max attachments = 1
    upload multiple files from powerapps to sharepoint document library

    3. Now, the Attachment control is ready to attach any file. Once you click on the Attach file link from the attachment control, it will redirect you to your local system to select the files.

    powerapps upload file from local

    4. Documents or files cannot be uploaded directly to a SharePoint document library from Power Apps; instead, a Power Automate flow must be created for this purpose.

    5. For that, go to the Power Automate section, select the Create new flow button, and click on the + Create from blank button, as shown below.

    power apps upload file to sharepoint

    6. Once you click on the “Create from blank” button, the trigger will be created as PowerApps (V2) by default. Then, you can choose the user input as a File.

    powerapps upload file to sharepoint

    7. Next, click on the + New step to add an action [Create a file] and provide the below information. Such as:

    • Site Address = Provide the specific SharePoint site address URL
    • Folder Path = Select the SharePoint document library where you are going to upload the Power Apps files
    • File Name = The File Name field requires a Expression -> [triggerBody()[‘file’][‘name’]
    • File Content = The File Content field should reference the file located within our flow trigger
    upload file to sharepoint library using powerapps

    8. Once it is done, Rename and Save the flow. You will now find the created flow under the Power Automate section, as shown below.

    upload files from powerapps to sharepoint document library

    9. Finally, insert a Button control and set its OnSelect property to the code below.

    OnSelect = PowerAppsUploadFileToSharePointDocumentLibrary.Run(
        {
            File: {
                name: First(Attach_File.Attachments).Name,
                contentBytes: First(Attach_File.Attachments).Value
            }
        }
    );

    Where,

    • PowerAppsUploadFileToSharePointDocumentLibrary = Power Automate flow name
    • name = It stores the filename and extension
    • Attach_File = Power Apps Attachment control
    • contentBytes = This contentBytes field holds a reference to the attachment file
    upload file from powerapps to sharepoint library

    10. Once your app is ready, Save, publish, and Preview the app. When the user uploads any file or document from the local device and clicks on the button control, the flow will trigger successfully, as shown below.

    upload file from power apps to sharepoint library

    11. Also, the file will stored in the SharePoint Online document library as well.

    This way, you can upload a single file from Power Apps to the SharePoint document library.

    power apps upload file

    Power Apps Upload Multiple Files to SharePoint

    Similarly, if you want to upload multiple files from Power Apps to the SharePoint document library, you can follow the code below to set the button control’s OnSelect property.

    OnSelect = ForAll(
        Attach_File.Attachments As Document,
        PowerAppsUploadFileToSharePointDocumentLibrary.Run(
            {
                File: {
                    contentBytes: First(Attach_File.Attachments).Value,
                    name: First(Attach_File.Attachments).Name
                }
            }
        )
    )

    Note:

    If you want to upload multiple files from Power Apps to SharePoint library, you should increase the Max attachments from 1 to another value.
    power app upload file to sharepoint

    Save, Publish, and Preview the app. Whenever the user selects multiple files from a local device and clicks on the button control, the flow will trigger successfully, and files will be stored in the document library.

    how to upload files to sharepoint library

    This is how we can work with Power Apps upload multiple files to the SharePoint library.

    How to Add Metadata to the SharePoint Document Library

    Suppose you want to upload the file, including the metadata from Power Apps, to the SharePoint document library; follow the below steps. Such as:

    1. On the Power Apps Screen -> Insert an Edit form above the Attachment control and set its DataSource as:

    DataSource = 'Policy Documents'

    Where,

    • ‘Policy Documents’ = SharePoint document library
    How to Add metadata to the SharePoint document library

    2. Now, edit the current flow, like adding Text input for File Properties -> Add Compose action and setting Its Inputs as a SharePoint online site, as shown below.

    How to Add Power Apps metadata to the SharePoint document library

    3. Next, add another action [Update file properties] and provide the below information. Such as:

    • Site Address = Provide site address from Compose outputs
    • Library Name = By default, it will take library code based on the outputs
    • ID = You can Seect dynamic content of ItemID
    • Item = For Item property, you can use the following expression like, (json[triggerBody()[‘text’]) using File Properties
    upload file from powerapps to sharepoint online library

    4. After saving the flow, insert a Submit icon on the Power Apps Screen and set its OnSelect property to the code below.

    OnSelect = PowerAppsUploadFileToSharePointDocumentLibrary.Run(
        JSON(
            frm_Records.Updates,
            JSONFormat.IncludeBinaryData
        ),
        {
            file: {
                name: First(Attach_File.Attachments).Name,
                contentBytes: First(Attach_File.Attachments).Value
            }
        }
    )

    Where,

    • JSON() = We can use this Power Apps JSON() function to add metadata to the SharePoint document library
    powerapps upload file to sharepoint document

    5. Save, Publish, and Preview the app. Once the user adds metadata, including the attachment, and clicks on the save icon, the flow will trigger successfully, and you will get the attachment file, including metadata, on the SharePoint library.

    powerapps upload multiple files to sharepoint library

    I trust this Power Apps tutorial will be helpful. If you have any requirements related to uploading a Power Apps file to the SharePoint document library, you can follow the above examples to do it.

    Also, you may like:

    comment_count comments
    Oldest
    Newest
    Oldest

    Comment as a guest:

    >