cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ghrimm
Level: Powered On

Attachments control: Get file properties/Restrict file type

Has anyone here been able to use the Attachments control and get a file's properties (ie. file name, file type)? Is there a way to restrict the file types a user can upload using the Attachments control in PowerApps?

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft Employee

Re: Attachments control: Get file properties/Restrict file type

Hello @ghrimm,

Currently there's no way to prevent of attaching certain files by type. You can however check the file extensions of "attached" files, before those files are submitted to SharePoint. You could allow the user to attach any files but disable the "Submit" button if the user attached restricted files. 

Here is how to check the file extension of the first attached file: 

Last(Split(First(Attachments_Control.Attachments).Name, ".")).Result

You can use any enumerations (ForAll for example) to validate all the files this way.

Hope this helps.

6 REPLIES 6
Microsoft Employee

Re: Attachments control: Get file properties/Restrict file type

Hello @ghrimm,

Currently there's no way to prevent of attaching certain files by type. You can however check the file extensions of "attached" files, before those files are submitted to SharePoint. You could allow the user to attach any files but disable the "Submit" button if the user attached restricted files. 

Here is how to check the file extension of the first attached file: 

Last(Split(First(Attachments_Control.Attachments).Name, ".")).Result

You can use any enumerations (ForAll for example) to validate all the files this way.

Hope this helps.

ghrimm
Level: Powered On

Re: Attachments control: Get file properties/Restrict file type

Thanks for the simple workaround. That returns exactly what I need for hiding/showing controls.

trev1
Level: Power Up

Re: Attachments control: Get file properties/Restrict file type

Would you be able to show an example with screenshots from the rule?

Highlighted
ghrimm
Level: Powered On

Re: Attachments control: Get file properties/Restrict file type

In my OnAddFile property, I have the following:

 

UpdateContext({IsADocx : Last(Split(First(dcv_Attachments.Attachments).Name, ".")).Result = "docx"})

KayBell
Level: Powered On

Re: Attachments control: Get file properties/Restrict file type

This works great for a single attached file, but doesn't work on multiple attachments.  Only works on first attachment.  Is there a way to check all attachments? 

markbloomdxc
Level: Powered On

Re: Attachments control: Get file properties/Restrict file type

You can check multiple attachments as you upload them one by one

Using the previous formula (but checking the last attachment, not the first) in the "OnAddFile" action field of the attachments card:

If(Last(Split(Last(DataCardValue15.Attachments).Name, ".")).Result = "xlsx",Set(VarContainsXLSX,true))

Will for example check if there are any excel documents uploaded and set a variable.

This won't detect if someone uploads an xlsx and then deletes it.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 65 members 4,635 guests
Please welcome our newest community members: