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 to view and replac...
Power Apps
Answered

How to view and replace the existing file/document in library in attachment control using powerapps

(0) ShareShare
ReportReport
Posted on by

"Hello,

In my PowerApp, I have a form where I copied the attachment control from a list.

ThaarA1424_0-1700734758067.png

I would like to view the files of the library selected from the gallery, and I also want to replace the existing file by deleting the old file.

I hope someone can help.

Categories:
  • v-yueyun-msft Profile Picture
    Microsoft Employee on at

    Hi, @ThaarA-1424 

    According to your description, you want to show and update the attachments in Power Apps.

    First , Currently Patches don't support Attachments, so we can't use the Patch function alone to modify our Attachments.

    You can refer to :
    Solved: Saving attachments using Patch - Power Platform Community (microsoft.com)
    We need to use Form to update Attachments.

     

    So , for your need , you can just add a Form control and use use this code in the Form-Item:
    Gallery.Selected

     

    Then we can use "SubmitForm(Form)" to update the attachemnts.

    And if you do not other fields , you just need to delete the DataCard in your Form control.

    vyueyunmsft_0-1700791032869.png

     

     

     

     

    If I misunderstand what you mean, you can describe your needs and your expected outcomes in detail so that we can better help you.


    Best Regards,

    Yueyun Zhang

     

     

  • ThaarA-1424 Profile Picture
    on at

    Thank you for the Response @v-yueyun-msft ,

    I would like to clarify one thing: this is a library, not a list. I'm not sure if it is possible to achieve this with library documents. I would like to view the files from the selected gallery in the library, and I also want to replace the existing file by deleting the old file.

     

    Thanks

     

  • Verified answer
    v-yueyun-msft Profile Picture
    Microsoft Employee on at

    Hi , @ThaarA-1424 

    According to your description, you are connecting the document in sharePoint ?

    If this , you can try to use this:
    Gallery-OnSelect:

    ClearCollect(colAttach,ForAll(Table(Gallery3.Selected),{DisplayName:ThisRecord.'File name with extension', Id:ThisRecord.'File name with extension',Value:ThisRecord.'Link to item'} ));
    ClearCollect(GalSelected, Gallery3.Selected );

    Attachments- Items:

    colAttach

     

    As we can not get the fileContent from the Documents, so we need to add a Button-OnSelect:

    Set(Attac2, Attacher.Attachments);
    Set(IDItem,Value(updatethefile.Run(Gallery3.Selected.Identifier,Gallery3.Selected.hiddenFolderPath,First(Attac2).Name,First(Attac2).Value).id));
    Refresh(Documents); Reset(Gallery3);

    And we need to use the flow , first delete this file then create a new file . Because we do not have the replace file action in automate .

    vyueyunmsft_0-1700807131571.png

    Then we can configure Gallery-Default:

    If( IsBlank(LookUp(Documents,ID=Value(IDItem))) , First(Documents),LookUp(Documents,ID=IDItem) )

     

    And for this , we can just use it for the files instead of the folders.

    vyueyunmsft_1-1700807201611.png

     

     

    If I misunderstand what you mean, you can describe your needs and your expected outcomes in detail so that we can better help you.


    Best Regards,

    Yueyun Zhang

     

     

     

  • ThaarA-1424 Profile Picture
    on at

    Hello @v-yueyun-msft ,

    I've tested your solution, and it works well. However, it appears to delete the document along with its properties. My goal is to replace the file while preserving the existing properties and ensuring that the existing ID doesn't change. I've utilized this ID with several lists. Could you please provide guidance on achieving this?

    Thank you.

  • v-yueyun-msft Profile Picture
    Microsoft Employee on at

    Hi , @ThaarA-1424

    Thanks for your quick response! As searched for a long time and test it in my side. I found no way to directly replace the file in document due to we can not update the file extension in Power Automate or in Power Apps.

    For this , you can refer to :

    Solved: Renaming SharePoint file using REST API with Power... - Power Platform Community (microsoft.com)

     

    And if you want to keep other fields value for your file , you need to use the Update file properties to keep the value after recreating the new file:

    vyueyunmsft_0-1701052952127.jpeg

     

     

    And in my side , this is the only way to replace file by first deleting it and then create a new file...


    Best Regards,

    Yueyun Zhang

     

  • ThaarA-1424 Profile Picture
    on at

    Hello @v-yueyun-msft ,

    Thank you for your effort. In your solution, if I delete the file before creating it, the properties will also be deleted. In this case, how can I update the file properties? I'm not sure about what you are trying to convey. If there is no solution, I'll consider this topic concluded.

  • Verified answer
    v-yueyun-msft Profile Picture
    Microsoft Employee on at

    Hi , @ThaarA-1424 

    Thanks for your response!

    If your means the properties is the column in your document:

    vyueyunmsft_0-1701073018107.png

    You can just use the Update file properties to keep the properties :

    vyueyunmsft_1-1701073133891.png

    Then we can keep this column value if we change this file :

    vyueyunmsft_2-1701073182059.png

     

    Best Regards,

    Yueyun Zhang

     

  • ThaarA-1424 Profile Picture
    on at

    Hi @v-yueyun-msft ,

    I appreciate your effort. The formula in the button's Onselect property is a bit confusing. Could you please expand it for a clearer view? If my understanding is correct, I need to update each column in the button's OnSelect action. However, if I proceed this way, won't the unique ID be changed?

  • v-yueyun-msft Profile Picture
    Microsoft Employee on at

    Hi , @ThaarA-1424 

    The button -OnSelect code is this , i add a column value to pass to the flow:

    Set(Attac2, Attacher.Attachments);
    Set(IDItem,updatethefile.Run(Gallery3.Selected.Identifier,Gallery3.Selected.hiddenFolderPath,First(Attac2).Name,First(Attac2).Value,Gallery3.Selected.Category.Value ).id);
    Refresh(Documents); Reset(Gallery3);

     

    And you are right, the unique ID will be changed due to we create a new file in the document. There is no way to keep the unique ID.😭

     

    Best Regards,

    Yueyun Zhang

  • ThaarA-1424 Profile Picture
    on at

    Hi @v-yueyun-msft ,

    The ID is connected to a different list, so I can't change that. Anyway, I appreciate your time and efforts. I've marked it as a solution.

    Thank you

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 381 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 340

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard