Uploading To A SharePoint Document Library From Power Apps

Posted by

This post has been republished via RSS; it originally appeared at: Healthcare and Life Sciences Blog articles.

franz_506_0-1668197042546.jpeg

 

Pre-Requisites:

 

Rename the app's start screen. You should have access to Power App, 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

 

       franz_506_0-1668187159811.png

 

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

 

       franz_506_1-1668187159812.png

 

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.

 

        franz_506_2-1668187159813.png

 

  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.

 

        franz_506_3-1668187159815.png

 

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

 

        franz_506_4-1668187159816.png

 

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 arrow with stripes. Select this icon and click create flow.

 

        franz_506_5-1668187159818.png

 

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.

 

        franz_506_6-1668187159820.png

 

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.

 

 

       franz_506_7-1668187159821.png

 

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

 

       franz_506_8-1668187159823.png

 

 

  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:

 

      franz_506_9-1668187159824.png

 

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.