web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Disable the option to attach file types

(0) ShareShare
ReportReport
Posted on by
Would like to disable the user from being able to attach files that are not either, ".doc, .pdf, .xlsx". Trying to upload an ".xlsx" file type.
 
I have tried the code below found in an old post, where it checks to see if the extensions are in the name.
ForAll(Self.Attachments,
If(
    Not(
        Or(
            EndsWith(Name, ".docx"),
            EndsWith(Name, ".doc"),
            EndsWith(Name, ".pdf"),
            EndsWith(Name, ".xlsx") 
        )
    ),
    Notify("Only .docx, .doc, .pdf, or .xlsx file types are allowed", NotificationType.Error);
    Reset(Self)
    Collect(colAttachments, value)
)
)
 
Also tried the code below by saving all the attachments into a collection and then trying to remove them from the collection but it deletes all the items in the collection. Printed the name in a data table and the DisplayName does contain the extension.
ClearCollect(colAttachments, Self.Attachments);
RemoveIf(colAttachments, Not(".pdf" in DisplayName) Or Not(".xlsx" in DisplayName))
 
Categories:
I have the same question (0)
  • Suggested answer
    AndrianaO Profile Picture
    213 Moderator on at
    Disable the option to attach file types
    Hi! Your last formula gives wrong result because of Or. You need to use And instead.
     
    ClearCollect(colAttachments, Self.Attachments);
    RemoveIf(colAttachments, Not(".pdf" in Name) And Not(".xlsx" in Name))
     
    Let me know if this helps.
  • mp13 Profile Picture
    39 on at
    Disable the option to attach file types
    This is what I use in the 'OnAddFile' property of my attachment control. I only want .xlsx files uploaded, so this works for me. You could add more with an Or statement. 
     
    If(
        Right(
            Last(Self.Attachments).Name,
            4
        ) <> "xlsx",
        Notify(
            "You can only attach .xlsx files",
            NotificationType.Error
        );
        Reset(Self)
    )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 663 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 398 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 235

Last 30 days Overall leaderboard