| Zoha Zulfiqar
In Canvas Apps, an attachment control is only available inside a form. You can’t directly insert an attachment control from the insertion bar to place it anywhere in a canvas app. First you need to insert a form from insertion bar, only then you access the attachment control inside of it.
The good part is, an attachment control is found only inside a form but it doesn’t mean that it can only work inside a form. It can be used outside of a form, anywhere in your canvas app, just by copying it from a form and pasting it wherever you want to use it.
Getting it out of a form is easy but when it comes to dealing with it, it gets a little trickier. Let’s explore it with a simple demonstration to understand how it actually works.
I have created a dataverse table called FileAttachments with a custom column named AttachFile. When you create a table with file type columns, make sure to check “Enable Attachments (including notes and files”).
After that, create a column inside that table with data type called File so that it can only store file attachments.
Now we are done with the table, let’s move on to the canvas app. I have created a simple canvas application to show how to use an attachment control without of a form. Let’s start by inserting a form in the canvas app and adding our FileAttachments table to it as the datasource. Only add the AttachedFile field to the form.
After that, just copy that attachment control and paste it outside the form in your canvas app and delete the form. Also, add a button for patching the attachment into dataverse and add the following code to its onSelect property.
In this code, I have used a patch function to store the attachment file to the dataverse table called FileAttachments. Attachedfile is the column name and AttachedFileResponse is the name of attachment control that I have used.
Attachment control has a property where you can select the maximum amount of attachments to be stored in it. In this demonstration, I have limited it to only one attachment, so I’m using first function to access the first and only attachment file from its AttachedFileResponse. Attachments property.
Moreover, an attachment has two parameters called name and value, both are necessary to store in dataverse so the file can be stored properly.
Now let’s try adding a file through the canvas app. Click on Upload file in the attachment control and select any file, click on Add File button.
After patching, if you go back to the table and see the patched row, AttachedFile column will look like this:
If you need to see the actual file, you can create a model-driven app for it or you can just click on edit record and see that the file is properly attached.
Easy, right? Now you can easily use attachment control anywhere in your canvas app without using a form!
Join us next time, as we continue our journey of learning canvas apps.Click here to learn more about Imperium's Power Apps Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.