| 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”).

CanvasAppFileUpdate-1

After that, create a column inside that table with data type called File so that it can only store file attachments.

CanvasAppFileUpdate-2

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.

CanvasAppFileUpdate-3

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.

CanvasAppFileUpdate-4

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.

CanvasAppFileUpdate-5

After patching, if you go back to the table and see the patched row, AttachedFile column will look like this:

CanvasAppFileUpdate-6

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.

CanvasAppFileUpdate-7

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.



About The Blog

Stay updated with what is happening in the Microsoft Business Applications world and initiatives Imperium is taking to ease digital transformation for customers.


More About Us

We provide guidance and strategic oversight to C-Suite and IT Directors for on-going implementations. Feel free to give us a call.

1 331 250 27 17
Send A Message

Ready to Start?

Get a personalized consultation for your project.

Book a Meeting