Blog Post

Healthcare and Life Sciences Blog
3 MIN READ

Uploading To A SharePoint Document Library From Power Apps

Francisco_Ruiz's avatar
Nov 11, 2022

 

Pre-Requisites:

 

You should have access to Power Apps, Power Automate, and a SharePoint site before you begin this tutorial.

 

Why:

 

You'd like to be able to make users selected local documents publicly visible on a SharePoint site and there is no built-in controller for Power Apps when attempting to attach general local files.

 

Steps:

 

  1. Create Power App Solution

 

       

 

Rename the app's start screen.

 

  1. Create a New SharePoint Document Library Called Files

 

Make sure to include a column called 'Name' and any other relevant column titles.

 

  1. Insert an Attachments Control in Power App

 

       

 

Add a button and label so that your app matches our Tree View.

 

  1. Work-A-Round for an Attachments Control in Power App

 

Now go to the data connections tab and click the 'add data' icon. We will want to connect any existing SharePoint list. It is crucial that you do not select the document library we created earlier as this will not allow us to grab the attachments controller we are looking for.

 

        

 

  1. Create a New Edit Form With Our SharePoint List as the Data Source

 

A field called attachments should appear automatically but if it does not you can edit the fields that are visible in the right-side menu.

 

        

 

You should cut the Attachments control out of the form, delete the form, and rename the control.

 

        

 

We must now edit the attachment control's properties to make sure that we are getting the right behavior. The items property should be Blank()

the DisplayMode property should be DisplayMode.Edit, the Max Attachment and Max Attachment Size properties should be set to a reasonable value.

 

You may now delete the connection to SharePoint as we will no longer need it.

 

  1. Triggering a Power Automate Flow for a SharePoint Library Action

 

Documents cannot be uploaded directly from a Power App to SharePoint so we must create a flow which will handle that for us. On the left-side menu there is an arrow with stripes. Select this icon and click create flow.

 

        

 

Choose create from blank and rename your flow.

 

You will have to delete the standard trigger using its right-hand ellipses and add the PowerApp V2 trigger. We will need the ability to upload files so that is why we need the V2 trigger.

 

        

 

Add file input to the trigger and make sure that it is required using the left-hand ellipses

 

Add a SharePoint action to the flow: Create File. Use your SharePoint site address and document library folder path as inputs. The File Content field should reference the file found in our flow trigger.

 

 

       

 

In order to get a dynamic file.name you must enter this into the expression tab.

 

       

 

 

  1. Connect the Flow in Power Apps

 

In the Power Automate menu select 'add flow' and add our new flow we made. In the button's onChange property write the following:

 

      

 

The {file: … portion is critical as this is needed to attach the file content to the PUT request being generated by Power Apps.

 

After testing if you are encountering any errors make sure to check that the Power App V2 trigger has the file input set as required and that you are passing the parameters of the file exactly as shown above.

 

Conclusion

 

This was a good example of the various workarounds needed to get a Power App connected to a SharePoint list.

Updated Nov 11, 2022
Version 5.0
  • schneidies's avatar
    schneidies
    Copper Contributor

    Update on my last comment as there was an inquiry:

     

    The fix was to remove the {file:  }...apparently that become obsolete at some point or there was some other change to Microsoft/Power Apps.

     

    My working code looks like this:

     

     

    Hope that helps someone!

     

  • AmyraNajwa's avatar
    AmyraNajwa
    Copper Contributor

    Hello! this is such a great example for a beginner like me. I am currently working on an app that would let employees in the company to upload their details in pdf form. However im currently running into a complication at the moment. It seems that other employees cant upload their files to sharepoint except the owner of the sharepoint only. Do you have any ideas or solution to this issue? Thank you!

  • schneidies's avatar
    schneidies
    Copper Contributor

    Hi Francisco! I appreciate the great post and how-to.

     

    I'm running into problems attempting to implement this:

    1. My button does not have an 'OnChange' property, only 'OnSelect'
    2. When I attempt to run my flow utilizing the OnSelect property, it is rejecting the formula/syntax even though I've gone over it with a fine-toothed comb:

    Is it possible that the way the formula needs to be formatted has changed from when this post was created?
    I believe my flow is correctly asking for the right parameters:

    1.  

    2.  

    Thank you for your time!

    - Alison