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 :

View PDF List attachments in PDF viewer

WarrenBelz Profile Picture WarrenBelz 153,026 Most Valuable Professional
The process for viewing SharePoint Library attachments in the PDF viewer has been well documented, but what about SharePoint List attachments ? This blog will discuss a fairly straight-forward method of adding this to the user experience.

Firstly, you need a Gallery with the Items (if you only have PDF files, you do not need the Filter).
Filter(
   AttachmentControlName.Attachments,
   EndsWith(
      Lower(Name),
      "pdf"
   )
)

You can put the Name (Text Label with ThisItem.Name ) and possibly an Image control with the Image property of
https://yourdomainname.sharepoint.com/_layouts/15/getpreview.ashx?path=" & ThisItem.AbsoluteUri

Note that this will not resolve the thumbnail on a mobile device app.

Now add an icon (Icon.DocumentPDF is a good one). You are also going to need the ID of the record that the files are attached to. The OnSelect of the icon (do not enter this until you have written and linked the Flow below or you will get an error)
UpdateContext(
   {
      varPDF: YourFlowName.Run(
         YourIDHere,
         ThisItem.Name
      ).result
   }
)

The Flow is as below


Now add a PDF viewer with the Document property of 
varPDF

and add the OnSelect to the icon as set out further above.

To sumarise what is happening here -
  1. The Flow is being called from Power Apps and supplied the ID of the SharePoint List record and the Name of the file to be viewed.
  2. A String Variable PDFContent is then initialised (it will be needed later).
  3. Get Attachments is then used to get the Attachments Metadata from the record with the ID sent.
  4. An Apply to each function is then needed as the Flow will retreive all attachments from that record.
  5. A Condition is then applied to check if the Name of the file being tested is the one you need.
  6. If it is, the Content of the target attachment is retreived using Get attachment content.
  7. The ​​​​​​​PDFContent Variable is then updated by converting the content to a String using the dataUri function.
  8. The "loop" will only address one file with a matching name, so the value in the Variable will be the correct one.
  9. The Variable content is then sent back to Power Apps.
  10. Power Apps then sets a local Context Variable varPDF, which is used as the value in the PDF Viewer.
code snippet widget

Comments