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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Display SharePoint Lis...
Power Apps
Suggested Answer

Display SharePoint List Attachments in Power Apps | Viewer Component

(0) ShareShare
ReportReport
Posted on by 149
Hi.

I've recently used Reza Dorrani's helpful 'Display SharePoint List Attachments in Power Apps | Viewer Component' video to add a document viewer to my Power App. His component is working great and allows my users to access SharePoint list item attachments from a gallery within the app. Exactly what was needed.

I just have one issue, which I'm hoping someone can help with. The component appears to display the first thumbnail from the top item in the gallery by default. Which is fine, but my app also contains a series of filter controls to allow the user to filter the gallery items. Whenever the gallery is filtered, unless the filter result includes the top item, the document viewer displays as empty until the next time an item from the gallery is selected.

I'm struggling to establish if the component can be tweaked to always show the first thumbnail from the top item in the gallery, irrespective of whether the gallery has been filtered or not.

Thanks in advance.           
Categories:
I have the same question (0)
  • Suggested answer
    venturemavenwill Profile Picture
    1,189 Super User 2025 Season 2 on at
    Have you tried the AllItems property of the gallery? I am guessing that the current problem is that you are getting the first item of the attachment property, so if you get the first item of the items displayed in the gallery, it should work. 
  • Matt-991599 Profile Picture
    149 on at
    Thanks venturemavenwil,

    I appreciate you responding so quickly.

    I'm still a bit of a Power Apps novice I'm afraid. What are you recommending that I change? And where?  
  • Suggested answer
    Solutionm8 Profile Picture
    92 on at
    Hi Matt

    Now, I have not seen Reza Dorrani's video, but I assume that the component uses some sort of gallery.selected logic. When the users utilize filters, the gallery.selected returns blank, because no item is selected in the gallery after the filter is applied.

    One approach is to make some logic on your components image property (I assume it is an image control), that checks if yourgalleryname.selected returns blank.
    If it does not return blank, it should display the selected items attachment. If does return blank it should display the first item's attachments from the list.

    Displaying the the gallery's first item's first attachment in an image control:
    First(First(Gallery1.AllItems).Attachments).AbsoluteUri
     
    The full logic on my image control's image property:
    If(IsBlank(Gallery1.Selected),First(First(Gallery1.AllItems).Attachments).AbsoluteUri,First(Gallery1.Selected.Attachments).AbsoluteUri)


    I hope this can help you. 
    /Solutionm8
     
    -----------------------------------------------------------------------------------------------------------------------------------
    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.
  • Matt-991599 Profile Picture
    149 on at
    Hi Solutionm8

    Thanks for taking the time to respond and trying to help. I really appreciate it.

    I've attached the code from the component's image property. Unfortunately my coding skills are quite limited, so I'm not sure where to incorporate your suggested logic. Any guidance you can give me will be great. 
     
    With(
        {
            fileExtension: Last(
                ForAll(Split(
                    ThisItem.DisplayName,
                    "."
                ), {Result: ThisRecord.Value})
            ).Result
        },
        If(
            fileExtension in [
                "xlsx",
                "xls",
                "csv"
            ],
           "data:image/svg+xml;utf8, " & EncodeUrl("<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2048 2048'><path d='M2048 475v1445q0 27-10 50t-27 40-41 28-50 10H640q-27 0-50-10t-40-27-28-41-10-50v-256H115q-24 0-44-9t-37-25-25-36-9-45V627q0-24 9-44t25-37 36-25 45-9h397V128q0-27 10-50t27-40 41-28 50-10h933q26 0 49 9t42 28l347 347q18 18 27 41t10 50zm-384-256v165h165l-165-165zM261 1424h189q2-4 12-23t25-45 29-55 29-53 23-41 10-17q27 59 60 118t65 116h187l-209-339 205-333H707q-31 57-60 114t-63 112q-29-57-57-113t-57-113H279l199 335-217 337zm379 496h1280V512h-256q-27 0-50-10t-40-27-28-41-10-50V128H640v384h397q24 0 44 9t37 25 25 36 9 45v922q0 24-9 44t-25 37-36 25-45 9H640v256zm640-1024V768h512v128h-512zm0 256v-128h512v128h-512zm0 256v-128h512v128h-512z' fill='Purple'></path></svg>"),
            If(
                fileExtension in [
                    "png",
                    "jpg",
                    "jpeg",
                    "gif"
                ],
                ThisItem.Value,
                If(
                    "appres://" in ThisItem.AbsoluteUri,
                     "data:image/svg+xml;utf8, " & EncodeUrl("<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2048 2048'><path d='M1115 0l549 549v91h-640V0h91zm37 512h293l-293-293v293zm384 384V768h128v128h-128zm0 256v-128h128v128h-128zm0 256v-128h128v128h-128zm0 256v-128h128v128h-128zm0 256v-128h128v128h-128zm-256 0v-128h128v128h-128zm-256 0v-128h128v128h-128zm-256 0v-128h128v128H768zm-256 0v-128h128v128H512zm-256 0v-128h128v128H256zm0-1024V768h128v128H256zm0-256V512h128v128H256zm0-256V256h128v128H256zm0-256V0h128v128H256zm256 0V0h128v128H512zm256 0V0h128v128H768zM256 1152v-128h128v128H256zm0 256v-128h128v128H256zm0 256v-128h128v128H256z' fill='Purple'></path></svg>"),
                    If(
                        fileExtension in [
                            "pdf",
                            "pptx",
                            "docx",
                            "ppt",
                            "doc"
                        ] && IsBlank(Acceleration.X),
                        "https://XXXXXX.sharepoint.com/_layouts/15/getpreview.ashx?path=" & (ThisItem.AbsoluteUri) & "&resolution=6",
                        If(
                            fileExtension in "svg" && IsBlank(Acceleration.X),
                            ThisItem.Value,
                            "data:image/svg+xml;utf8, " & EncodeUrl("<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2048 2048'><path d='M1115 0l549 549v91h-640V0h91zm37 512h293l-293-293v293zm384 384V768h128v128h-128zm0 256v-128h128v128h-128zm0 256v-128h128v128h-128zm0 256v-128h128v128h-128zm0 256v-128h128v128h-128zm-256 0v-128h128v128h-128zm-256 0v-128h128v128h-128zm-256 0v-128h128v128H768zm-256 0v-128h128v128H512zm-256 0v-128h128v128H256zm0-1024V768h128v128H256zm0-256V512h128v128H256zm0-256V256h128v128H256zm0-256V0h128v128H256zm256 0V0h128v128H512zm256 0V0h128v128H768zM256 1152v-128h128v128H256zm0 256v-128h128v128H256zm0 256v-128h128v128H256z' fill='Purple'></path></svg>")
                        )
                    )
                )
            )
        )
    )
     
  • Solutionm8 Profile Picture
    92 on at
    Hi Matt, 

    Is the image component inside a gallery component? if that is the case was is your current formular in that gallery's items property?


    Are you able to provide a screenshot of the app? That would make it a bit easier to identify a solution :)
  • Matt-991599 Profile Picture
    149 on at
    MorningSolutionm8,

    Hope you had a good evening and thanks for replying again.

    I've included a screenshot of the structure of the component. The formula I included in my last message is in the Image property of AttachmentImage.

    When the gallery on my app is filtered, everything (i.e, download icon, attachment name and number, attachment image) disappears from the viewer until another item in the gallery is selected. Unless the filter result includes the top item in the unfiltered gallery.

    Ideally, I'd like it to always display details of attachments on the top item in the gallery (whether it is filtered or unfiltered).  

    Hope this helps.  

  • venturemavenwill Profile Picture
    1,189 Super User 2025 Season 2 on at
    Are you handling the "Items" parameter of the gallery in the component with a custom parameter you've set up elsewhere?
    If so, can you post what PowerFx expression you are currently using for that parameter in the main app screen?
  • Matt-991599 Profile Picture
    149 on at
    Hiventuremavenwil,

    The formula on the Items property on the component on the app page is: 
    Gallery1.Selected.Attachments.

    Not sure if that's what you mean?

    Thanks.
  • Suggested answer
    venturemavenwill Profile Picture
    1,189 Super User 2025 Season 2 on at
    Exactly this:

    Since the property is Gallery1.Selected, unless something is selected by Gallery1, nothing will show up
     
    You can circumvent this by doing something like
     
    If(
        IsBlank(Gallery1.Selected),
        First(Gallery1.AllItems).Attachments,
        Gallery1.Selected.Attachments
    )
    Let me know if this solves your problem. 
  • Matt-991599 Profile Picture
    149 on at
    Almost, but not quiteventuremavenwil
     
    The download icon, attachment name and attachment number are now all visible in the document viewer when the gallery is unfiltered and when the gallery is filtered (see screenshot below). So we (i.e. you!) are definitely making progess. Thank you!

    Unfortunately though, most of the thumbnail images have now disappeared from the document viewer altogether. Even when the gallery is unfiltered. It's still displaying .xlsx and .png files, but none of the others (e.g. .pdf, .pptx, .docx). These were visible before.

    If you can resolve that one last thing for me somehow, then I think you've cracked it! 
     
     
     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard