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:
- Create Power App Solution
Rename the app's start screen.
- Create a New SharePoint Document Library Called Files
Make sure to include a column called 'Name' and any other relevant column titles.
- Insert an Attachments Control in Power App
Add a button and label so that your app matches our Tree View.
- 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.
- 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.
- 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.
- 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.0Francisco_Ruiz
Microsoft
Joined September 12, 2022
Healthcare and Life Sciences Blog
Follow this blog board to get notified when there's new activity