cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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 @Anonymous ,

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 @Anonymous ,

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 @Anonymous ,

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.

Hi @Anonymous ,

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.

Anonymous
Not applicable

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

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (4,923)