Restrict Attachment control in PowerApps to accept Excel files only

In one of the previous posts, we learnt how we can create a notification from Power Automate when a certain file-type is uploaded to a SharePoint Document Library.

In this post, we will learn how we can restrict Power Apps attachment control to accept only a certain file-type. We will use Excel file (.xlsx) as the accepted file-type, however this can be similarly customized to any file-type(s).

In the Attachment control, go the property OnAddFile and enter the following code:

UpdateContext(

    {

        validFileType: EndsWith(

            Lower(Last(AttachmentControl.Attachments).Name),

            "xlsx"

        )

    }

)


Now, the context variable that we have created, i.e. validFileType can be used to provide error message to the user, such as disabling the submit button or if using in-built Form, then putting in the errorMessage datacard.

Updating error message datacard:
Coalesce(
    Parent.Error,
    If(
        !IsBlank(DataCardValue4.Attachments) && !validFileType,
        "File must be in .xlsx format"
    )
)

Updating DisplayMode property of the submit button:
If(
    validFileType,
    DisplayMode.Edit,
    DisplayMode.Disabled
)

Comments

Popular posts from this blog

Generate QR code within Power Automate

Get start and last date of month using Power Apps