cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BhushanInamdar
Helper I
Helper I

How to check if file with same name has been attached in PowerApps?

I want user to add files with different names. Currently default PowerApps control allows attachment of files with same names. But, while saving the form it saves only 1 file. I want to restrict users from attaching files with same name.

 
 
1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @BhushanInamdar ,

Could you please share a bit more about your scenario?

How do you upload files within your canvas app? Using Attachments control?

Further, do you want to restrict uploading files with same file name?

 

Based on the needs that you mentioned, I assume that you use Attachments control within your Edit form to upload files, is that true?

 

I have made a test on my side, please consider take a try with the following workaround:

16.JPG

 

17.JPG

Set the OnAddFile property of the Attachments control (DataCardValue16) in your Edit form to following:

Clear(AttachmentsCollection);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      Collect(
             AttachmentsCollection,
             Name1
      )
);
Clear(Counter);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      If(
          CountIf(AttachmentsCollection, Value = Name1) > 1,
          Collect(Counter, 1),
          Collect(Counter, 0)
      )
);
If(
    Sum(Counter, Value) >= 1,
    Notify("Please do not upload duplicate files, please remove it", NotificationType.Error)
)

Set the OnRemoveFile property of the Attachments control in your Edit form to following:

Clear(AttachmentsCollection);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      Collect(
             AttachmentsCollection,
             Name1
      )
);
Clear(Counter);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      If(
          CountIf(AttachmentsCollection, Value = Name1) > 1,
          Collect(Counter, 1),
          Collect(Counter, 0)
      )
);
If(
    Sum(Counter, Value) >= 1,
    Notify("Please remove duplicates file", NotificationType.Error)
)

Set the OnSelect property of the "Submit" button to following:

If(
    Sum(Counter, Value)>=1,
    Notify("Please remove duplicates files form the Attachments control, then submit your form data", NotificationType.Error),
    SubmitForm(EditForm1)
)

Note: DataCardValue16 represents the Attachments control in my Edit form, on your side, you should replace it with actual control name from your Edit form

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Carsten_Growth
Power Apps
Power Apps

As you can see from the sample (attachment), the name of both files would be the same before saving. You could check for this and avoid the Patch to run, before this is going to be corrected by the user.

 

Inside my example you can see that

First(DataCardValue7.Attachments).Name

will contain Gradient.PNG which equals all other Attachments.Name as well 

Hi @BhushanInamdar ,

Try putting this on your Save script

ClearCollect(
    colAtt,
    YourAttachmentControlName.Attachments
);
If(
    CountRows(
        Distinct(
            colAtt,
            Name
        )
    ) <> CountRows(colAtt),
    Notify("You have duplicate names",NotificationType.Error),
    SubmitForm(YourFormName)
)

 

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.

 

v-xida-msft
Community Support
Community Support

Hi @BhushanInamdar ,

Could you please share a bit more about your scenario?

How do you upload files within your canvas app? Using Attachments control?

Further, do you want to restrict uploading files with same file name?

 

Based on the needs that you mentioned, I assume that you use Attachments control within your Edit form to upload files, is that true?

 

I have made a test on my side, please consider take a try with the following workaround:

16.JPG

 

17.JPG

Set the OnAddFile property of the Attachments control (DataCardValue16) in your Edit form to following:

Clear(AttachmentsCollection);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      Collect(
             AttachmentsCollection,
             Name1
      )
);
Clear(Counter);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      If(
          CountIf(AttachmentsCollection, Value = Name1) > 1,
          Collect(Counter, 1),
          Collect(Counter, 0)
      )
);
If(
    Sum(Counter, Value) >= 1,
    Notify("Please do not upload duplicate files, please remove it", NotificationType.Error)
)

Set the OnRemoveFile property of the Attachments control in your Edit form to following:

Clear(AttachmentsCollection);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      Collect(
             AttachmentsCollection,
             Name1
      )
);
Clear(Counter);
ForAll(
      RenameColumns(DataCardValue16.Attachments, "Name", "Name1"),
      If(
          CountIf(AttachmentsCollection, Value = Name1) > 1,
          Collect(Counter, 1),
          Collect(Counter, 0)
      )
);
If(
    Sum(Counter, Value) >= 1,
    Notify("Please remove duplicates file", NotificationType.Error)
)

Set the OnSelect property of the "Submit" button to following:

If(
    Sum(Counter, Value)>=1,
    Notify("Please remove duplicates files form the Attachments control, then submit your form data", NotificationType.Error),
    SubmitForm(EditForm1)
)

Note: DataCardValue16 represents the Attachments control in my Edit form, on your side, you should replace it with actual control name from your Edit form

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @BhushanInamdar ,

A couple of choices here - you might try mine and if it does not do the job you need, the response from @v-xida-msft goes into a lot more functionality.

Thank you @v-xida-msft !! This is exactly what I wanted. I searched this for hours! 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,989)