Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

same file name exists in the attachment control

Like (1) ShareShare
ReportReport
Posted on 6 Oct 2024 11:45:54 by 310
Hi,
How to check if same file name are attached into attachment control at same time?
Thanks!
Categories:
  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 144,238 on 07 Oct 2024 at 03:35:12
    same file name exists in the attachment control
    The code from mmbr1606 is correct, except you do not need quotes "" around the GroupBy parameters and DisplayName needs to be Name. An alternative is below (to be used OnAddFile of the attachment control), but the main reason for my post was that also you need to know that you cannot have two files of the same name in an attachment control - the second one will replace the first one when saved.
    If(
       CountRows(
          Filter(
             Self.Attachments,
             Name = Last(Self.Attachments).Name
          )
       ) > 1,
       Notify(
          "File already stored",
          NotificationType.Error,
          4000
       );
       Reset(Self)
    )
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee
  • usaman45 Profile Picture
    usaman45 310 on 06 Oct 2024 at 23:58:24
    same file name exists in the attachment control
    I appreciate your assistance, but I encountered difficulties using the GroupBy function. I am uncertain about the cause; do you have any insights?
  • Verified answer
    mmbr1606 Profile Picture
    mmbr1606 10,071 on 06 Oct 2024 at 14:43:47
    same file name exists in the attachment control
    hey
     
    what you can try is the following:
    If(
        CountRows(
            Filter(
                GroupBy(AttachmentControl.Attachments, "DisplayName", "GroupedFiles"),
                CountRows(GroupedFiles) > 1
            )
        ) > 0,
        Notify("Duplicate file names are not allowed.", NotificationType.Error),
        // Proceed with your normal logic, like submitting the form or saving the data
        SubmitForm(EditForm)
    )
    
    this can be put in the onselect of a button for example. you need to rename to your needs
     
    let me know if it works, if it did  please mark as verified answer

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,238

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,290

Leaderboard