Adding Attachments In SharePoint Document Library Using Power Apps List Control

SharePoint helps users to effectively manage their contents with Lists and Libraries. Lists are meant for creating items and so can attach external files to it, but on the other hand Libraries are merely for creating predefined doc sets or to upload a file. A file is considered as one item and no further files can be added to the same item in a document library.

Consider a scenario where your vendor wants to maintain a document library with all the contents uploaded to that library and a supporting email attachment/pdfs/images attached to the same file uploaded as proof of evidence. Now the requirement is valid so you cannot get stuck to the limits rather obtain a solution outside of it.

Solution using Power Platform

Convert your SharePoint library from default form to PowerApps form and Edit the form in PowerApps designer. Then borrow the attachments control from any of the SharePoint lists because it supports multiple file attachments and a preview section. Store them in a collection and upload the file to a different SharePoint library with a Foreign Key as a reference using Power Automate flow. Create a new Gallery Control in the same form to display the files uploaded. Optionally the file uploaded can also be deleted by using another simple flow. Voila! The objective is fulfilled!

Now let’s see how to achieve this step by step

Create two libraries in my SharePoint site collection

  1. Vendor Documents: to collect files from the vendor
  2. VendorDocAttachments: to upload files for each item in the vendor documents

Columns to be created,

Library Name Column Name Type Remarks
Vendor Documents UploadFiles Multiple lines of text Just a placeholder section in the form
VendorDocAttachments VendorDocumentsID Single line of text Acts as a Foreign Key for the items in Vendor Documents library

Go to Vendor Documents library and customize the form using PowerApps

Adding attachments in SharePoint Document Library using Power Apps list control

Adding attachments in SharePoint Document Library using Power Apps list control

In the left menu, Tree View option will be selected (if not selected, click and go to the view). Under the Screens, expand the SharePointForm1 which displays the Title column.

In order to add the newly added column, after expanding the SharePointForm1 on the right side Edit Form property screen will appear. Click on the Edit fieldsàAdd fieldàUploadFiles (search for it) àAdd

Once the field is added, turn the DataCardValue2 visibility to off.

Adding attachments in SharePoint Document Library using Power Apps list control

Now we need an attachment controller which is by default not available in the SharePoint libraries.

So, open any list parallelly in a new tab and click customize the form using PowerApps. Under the Tree View -> Screens, expand the SharepointForm1 and copy the attachments control alone (here the name is DataCardValue3)

Go back to the Vendor Documents PowerApps form and paste the control under the newly added section

Note: While pasting the control PowerApps will request to confirm whether to unlock the data card and add the control. Click Unlock and add

Remove the default values (Parent.Default) to cancel the errors shown by the control

Adding attachments in SharePoint Document Library using Power Apps list control

Open the OnAddFile property; clear the false and add this

ClearCollect(collectionFiles,DataCardValue3.Attachments)

Formula: On the addition of files, forms collecting and storing the files in a temporary Collections (collectionFiles) in PowerApps from the attachments control field (DataCardValue3)

Adding attachments in SharePoint Document Library using Power Apps list control

OnRemoveFile property, add the same formula to refresh if any files are removed during preview

Adding attachments in SharePoint Document Library using Power Apps list control

Insert a Gallery Control

The data source of the Gallery will be the collection (collectionFiles) created earlier

In Gallery Control, remove all the elements except for Title and Image. Resize and make the control (Gallery1) and elements(Title1, Image1) are Invisible (this will act as a holder for temporary collection). Ensure the control is under the UploadFile DataCard, if the control is created outside of SharePointForm1, cut and paste inside the Datacard.

Adding attachments in SharePoint Document Library using Power Apps list control

Where Text to display on the elements are:

Title1.Text = ThisItem.Name

Image1.Image = ThisItem.Value

Now, insert a button where all the action lies on.

Rename the button to Upload Files and the Text on the button to “Upload Files”

Button action formulas:

In the button OnSelect property create another collection (collectionFilesGallery) where the “for loop” collects the files and stores as DataStream along with name of the files.

Clear(collectionFilesGallery); { purpose of this line is to clear any previous values }
ForAll(Gallery1.AllItems,Collect(collectionFilesGallery,{Title:Title1.Text,DataStream:Image1.Image}));

To be continued..

Please see: Detailed approach on how to bring in an attachment in a SharePoint library (where SP list will have attachments OOTB but not the library). This article is split into three parts for separating the tasks and this is Part 1