TIP: PowerApps restrict form to certain type of attachment

You have created a form to submit a file as attachment, you want that file should be of type .csv.

If user submits the file as .txt or any other format he or she should not be allowed to submit the form.

Here is the sample PowerApps form which we have restricted to single attachment and max attachment size.

(also, we have set attachment as required field)


Restrict to single attachment and max attachment size. (attachment as required field)

Click on attachments in PowerApps designer, change the required value to true


Now click on attach file


Change the Maxattachments to 1 and MaxattachmentSize to 1.


This is all easy as there are fields for it, now the real problem is to restrict the attachment to extension.

This can be done by updating the code on Submit button.(onSelect field as shown in the screenshot)


Here is the code just update the DataCardVallue2 to whatever your datacard called, also update .csv to the extension you want to restrict.

##############################################################################

ForAll(

DataCardValue2.Attachments.Name,

If(

Not(“.csv” in Name),

Collect(

collIncorrectAttachments,

{Name: Name}

)

)

);

If(

CountRows(collIncorrectAttachments) > 0,

Set(

varAttachmentsIncorrect,

true

);

Clear(collIncorrectAttachments),

Set(

varAttachmentsIncorrect,

false

);

Clear(collIncorrectAttachments);

SubmitForm(SharePointForm1)

)

#############################################################################

 

Now when you will submit the.txt file or any other extension file apart from .csv it will not allow the user to submit the form.

 

 

Thanks for reading………

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s