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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (67,925)