web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How i can remove all l...
Power Apps
Unanswered

How i can remove all list items attachments when submitting a form

(1) ShareShare
ReportReport
Posted on by 2,074 Season of Giving Solutions 2025

I have a SharePoint form which have attachments. now I want to remove all the attachments that are already saved to SharePoint and only add new attachments added to the form when submitting the form. is there a way to achieve this?

 

thanks

Categories:
  • Pro_User_365 Profile Picture
    546 on at

    Hi @johnjohnPter ,

    1. Before submitting the form, loop through the existing attachments using the ForAll function along with RemoveIf to delete them from the SharePoint list item.
    2. Add the new attachments by collecting them in a temporary collection and then submitting them with the form

     

    // To clear existing attachments
    ForAll(Gallery1.AllItems, RemoveIf(Attachments, ID = Parent.Default.ID));
    
    // To add new attachments
    // Assume you have collected new attachments in a collection called 'colNewAttachments'
    ForAll(colNewAttachments, AddAttachment(SharePointListName, ID, FileName, FileContent));

     

    Note: After receiving the answer, if you think it's helpful, please consider accepting it. 😊 Regards! Ali Shahzad

  • johnjohnPter Profile Picture
    2,074 Season of Giving Solutions 2025 on at

    @Pro_User_365 this will remove them from sharepoint, but when we submit the form again all the attached (old and new ) will get resubmitted? correcT?

     

    Also what is Attachments variable? and how i need to initiate it? 

  • Pro_User_365 Profile Picture
    546 on at

    @johnjohnPter , 

    1. Use ClearCollect to save the current attachments into a collection.
    2. Use ForAll combined with RemoveIf to remove attachments from SharePoint.
    3. Clear the attachment control to prevent re-submitting old attachments.
    4. Add new attachments from your temporary collection to SharePoint.

      Example:

      // Save current attachments to a collection
      ClearCollect(colCurrentAttachments, YourFormName.Attachments);
      
      // Remove attachments from SharePoint
      ForAll(colCurrentAttachments, RemoveIf(Attachments, ID = Parent.Default.ID));
      
      // Clear the attachment control
      Clear(YourFormName.Attachments);
      
      // Add new attachments to SharePoint
      ForAll(colNewAttachments, AddAttachment(SharePointListName, ID, FileName, FileContent));
      
      // Submit the form
      SubmitForm(YourFormName);

      By doing this, you ensure that only the new attachments are included when you submit your form.

     

  • johnjohnPter Profile Picture
    2,074 Season of Giving Solutions 2025 on at

    @Pro_User_365 have you tried what you have posted? as they do not make sense to me..  as 

    ClearCollect(colCurrentAttachments, YourFormName.Attachments);

    will contain both the new and the old attachments...

    Also what should the colNewAttachments contain??

     

  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard