| Mustafa Usmani
In this blog we will see how we can make some restrictions on accepting only correct format attachments that we need whenever a user is filling in a form with attachment column in it.
In our scenario, whenever a user selects any other files except pdf / png / jpg / jpeg, they are shown a message under the attachment data card that they should re-check their files as one or more has incorrect format. This is the end result:
In order to achieve that, insert a form and add attachments column in it so we can get attachment data card.
Now follow these steps:
- Look for OnAddFile and OnRemoveFile attributes in your attachments datacard and
write this code below:
- For OnAddFile
-
- For OnRemoveFile
- Where DataCardValue1_1 is my attachment’s data card and we are checking all the attachment’s name whether they end with the correct format or not.
- Finally add a label below it and on its Visible property, add this condition:
- So whenever there’s a wrong format file in the data card, this label will be shown. You can customize the logic in order to achieve your desire goal but the main key component is the IsMatch function here that compares the attachment’s name with a regular expression (regex) and checks if the name “ends” with characters that are given in the regex.
I would highly recommend to explore IsMatch function more as it is really helpful in many situations.
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.