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 Platform Community / Forums / Power Apps / Allow only some file t...
Power Apps
Unanswered

Allow only some file types as attachments

(0) ShareShare
ReportReport
Posted on by 1,625

Hello,

 

Is there a way I can restrict only certain file types to be uploaded via a Power Apps form (canvas app) linked to SharePoint Online.

Currently I want only PDF to be attached to my form, is this possible?

 

I've tried something like this:

Created a label - LblAttachmentWarning

On the Visible property of the label:

If(!".pdf" in Concat(DataCardValue38.Attachments.Name,Name&","),false)

On the submit button Visible property:

!LblAttachmentWarning.Visible

 

But I dont get the error appear when i upload a non PDF or even when i upload a PDF

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    152,847 Most Valuable Professional on at
    Re: Allow only some file types as attachments

    Hello @Lefty ,

    This on the OnAddFile properties of the Attachments card: (I will call the card AttachmentsCard) to generate an error message hopefully the user will acknowledge and set a variable you could disable the form save or something else on (I don't know of a way of clearing the attachment control)

    If(
     Last(
     Split(
     Last(
     AttachmentsCard.Attachments).Name,
     ".")
     )
     .Result <> "pdf",
     Notify(
     "Only PDF files can be attached",
     NotificationType.Error
     );
     UpodateContext({vAtrErr:true})
     )
     )
    )

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Lefty Profile Picture
    1,625 on at
    Re: Allow only some file types as attachments

    HI @WarrenBelz 

     

    I've tried your suggestion on the Datacard but getting a few errors:

     

    If(
    Last(
    Split(
    Last(
    Attachments_DataCard1.Attachments).Name,
    ".")
    )
    .Result <> "pdf",
    Notify(
    "Only PDF files can be attached",
    NotificationType.Error
    );
    UpodateContext({vAtrErr:true})
    )
    )
    )

     

    Noticed that my initial question works if i say:

     

    Visible fx: If(".png" in Concat(DataCardValue38.Attachments.Name,Name&","),true)

     

    But I dont want to name all the file types, rather i want to say if its not PDF show the error, then i disable the save button, but cant get that fx to work either

  • WarrenBelz Profile Picture
    152,847 Most Valuable Professional on at
    Re: Allow only some file types as attachments

    Hi @Lefty ,

    Without testing the issue with the first formula, I will try something hopefully less complex - your coding skills are obviously well up to extrapolating from this.

    The formula for testing the extension of the first attachment should be

    Last(
     Split(
     First(
     DataCardValue38.Attachments
     )
     .Name, 
     "."
     )
    )
    .Result

    So if this result is not "pdf", you should have something to test and hide/disable. Happy to help further if required.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up

  • WarrenBelz Profile Picture
    152,847 Most Valuable Professional on at
    Re: Allow only some file types as attachments

    HI @Lefty ,

    I have had some more time to try to give you a more complete solution and have tested this on one of my Attachment controls successfully.

    Firstly, the target is the Attachment Control, not the Card it is contained in - I will call yours FileAttach in the code below. I suggest you put this on your save button

    If(
       Last(
          Split(
             First(
                FileAttach.Attachments
             ).Name,
             "."
          )
       ).Value = ".pdf",
       SubmitForm(YourForm),
       Notify("Only PDFs allowed")
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Verified answer
    Lefty Profile Picture
    1,625 on at
    Re: Allow only some file types as attachments

    HI @WarrenBelz 

    Thanks for all your responses.

    I couldn't get your suggestion to work, but I've cracked my initial question, its easy when it works!

    I've used the following code on my labels visible property , and made my submit button invisible if my label shows: 

    If(Not(".pdf" in Concat(DataCardValue40.Attachments.Name,Name&",")),true)

    This allows me to only submit PDF

  • WarrenBelz Profile Picture
    152,847 Most Valuable Professional on at
    Re: Allow only some file types as attachments

    @Lefty ,

    This recent post of mine may also help.

  • Lefty Profile Picture
    1,625 on at
    Re: Allow only some file types as attachments

    HI @WarrenBelz 

     

    Thanks, going back a bit, i'm surprised you even found this post of mine!
    I think we got it to sort of work when I was looking for a solution for this.... but have bookmarked your new suggested post. 

  • russoedu Profile Picture
    50 on at
    Re: Allow only some file types as attachments

    The best way I found to solve this is by counting the number of attachments without the desired extension:

     

    CountRows(Filter(DataCardValue38.Attachments, Right(Name, 3) <> "pdf")) > 0

    Translating, I'm counting (CountRows) the result of the filter (Filter) of all attachments (DataCardValue38.Attachments) where the last 3 characters are not "pdf" (Right(Name, 3) <> "pdf")).

     

    If this filtered value is bigger than 0, it means some of the attachments are not PDF.

  • PandaRedCap Profile Picture
    54 on at
    Re: Allow only some file types as attachments

    Try this code on the "On Add file " of the Attachment control 

     

    If(Not(EndsWith(First(Self.Attachments).Name, ".pdf")) And Not(EndsWith(First(Self.Attachments).Name, ".docx")),Notify("Only pdf and docx files are allowed", NotificationType.Error); Reset(Self))

     

     

  • helpcuquin Profile Picture
    4 on at
    Re: Allow only some file types as attachments

    This will loop through all attachments (useful if you have more than one attachment). Add it to the OnAddFile:

    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);
            // Clear the attached files
            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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 757 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 322 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 209 Super User 2025 Season 2

Last 30 days Overall leaderboard