How To Restrict Uploading Different File Formats in Canvas App

| 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:

restrict uploading file formats

In order to achieve that, insert a form and add attachments column in it so we can get attachment data card.

restrict uploading file formats

Now follow these steps:

  • Look for OnAddFile and OnRemoveFile attributes in your attachments datacard and write this code below:
    • For OnAddFile

restrict uploading file formats

    • For OnRemoveFile

restrict uploading file formats

  • 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:

restrict uploading file formats

  • 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.


M
Chief Architect, Founder, and CEO - a Microsoft recognized Power Platform solution architect.

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