Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 3XyX3K4z/TrrottyNITLNy
Power Apps - Building Power Apps
Answered

Attachment Control outside a Form

Like (1) ShareShare
ReportReport
Posted on 6 Feb 2025 20:08:41 by 46

First of all, I know that an attachment control is not designed to be used outside of a form. Nevertheless, the Internet shows several examples of this, and my current solution approach is already quite advanced.

Before I describe my problem, here’s a brief explanation: Using a Dataverse table and a gallery, I created a dynamically adjustable form. The table defines the data fields along with their data types, which are then displayed in a gallery. Depending on the data field type, either a TextInput or an attachment control becomes visible within the gallery item. By pressing a button, the gallery is iterated over and, based on the type, either text is written into a column called “Daten” or, in the case of an attachment, into a column called “Daten Anhang”. The dynamic creation of the form and the data saving work flawlessly up to this point. I was also able to verify this with a model-driven app, where I can download the attachment that was uploaded via the canvas app without any issues.

Now to my problem:

In the canvas app, the uploaded attachment is correctly displayed in the attachment control; however, when I try to download it, my browser (MS Edge) gives me the error message that no file could be downloaded. Below are some images and code snippets for clarification.

// shorted function to patch attachment
Patch(
    '_REF Vorgang Prozess Datenfelder';
    LookUp(
        '_REF Vorgang Prozess Datenfelder';
        'Vorgang Prozess Datenfeld ID' = recVorgangProzessDatenfeld.'Vorgang Prozess Datenfeld ID'
    );
    If(
        IsBlank(First(recVorgangProzessDatenfeld.AnhangVorgangProzessDatenfeld.Attachments).Value);
        {'Daten Anhang': Blank()};
        {
            'Daten Anhang': {
                FileName: First(recVorgangProzessDatenfeld.AnhangVorgangProzessDatenfeld.Attachments).Name;
                Value: First(recVorgangProzessDatenfeld.AnhangVorgangProzessDatenfeld.Attachments).Value
            }
        }
    )
)

 

// Funtion to display attachment in attachmentcontrol
If(
    IsBlank(ThisItem.'Daten Anhang'.Value);
    Blank();
    First(
        Table(
            {
                FileName: ThisItem.'Daten Anhang'.FileName;
                Value: ThisItem.'Daten Anhang'.Value
            }
        )
    )
)
// Also not work
//ThisItem.'Daten Anhang'

Structure of the Gallery

 
 
Successfull uploaded attachment in canvas app
 

File can be found in model-driven app

 

Download from the Canvas app (bottom) failed, download from the model-driven app (top) succeeded.

Categories:
  • Verified answer
    LukasW Profile Picture
    46 on 08 Feb 2025 at 21:10:08
    Attachment Control outside a Form

    Yes, it doesn’t seem to work with a Dataverse table. Since I had hoped that my mechanism would work better outside of the gallery, I placed a button inside the gallery item that makes a dialog visible outside of the gallery, and I implemented my mechanism there. Unfortunately, I got the same result. The upload works, but the download does not. Now, I’ll simply include a form with a field for the attachment in the dialog. Then it should work… Hopefully… 😭

    Thanks for your help @WarrenBelz
  • WarrenBelz Profile Picture
    146,508 Most Valuable Professional on 08 Feb 2025 at 20:55:30
    Attachment Control outside a Form
    Hi @LukasW,
    I should have read back to your post properly. My structure is using SharePoint and works as described. Unfortunately, it does not work with Dataverse, though the comment on the attachment control I believe may be relevant.
  • LukasW Profile Picture
    46 on 08 Feb 2025 at 14:15:15
    Attachment Control outside a Form

    First of all, thank you very much for your answer. Unfortunately, I cannot get your workaround to work. When I insert the gallery into my gallery, the content of the nested gallery is not displayed, and on the other hand, the property “AbsoluteUri” is not available to me. Have I misunderstood the workaround?

  • WarrenBelz Profile Picture
    146,508 Most Valuable Professional on 06 Feb 2025 at 21:37:27
    Attachment Control outside a Form
    I have seen this issue posted before and you are correct that attachment controls are designed to be in Forms (and they do have quite useful purposes outside this - I use them to upload files), however putting one in a Gallery (and yours is inside a container as well) seems a "bridge too far" for the full expected functionality.
    What is disappointing is that that actually insert correctly and display the files, however do not download - I just did a test here to confirm and received the (expected) message File wasn't available on site.
     
    However there may be a workaround if all that you want to do is display the file names and open the file. Put a Gallery (nested) instead of the attachment control with the Items 
    ThisItem.Attachments
    with a Text Label
    ThisItem.DisplayName
    and then OnSelect
    Launch(ThisItem.AbsoluteUri)
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee

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

Thomas Rice – Community Spotlight

We are honored to recognize Thomas Rice as our March 2025 Community…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,508 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,369 Most Valuable Professional

Leaderboard
Loading started
Loading complete