AS ANY INTRANET MANAGER WILL TELL YOU, THE LAST THING YOU NEED is for your Site Editors to take copies of documents from elsewhere in the Intranet to add to their own document libraries. This will only result in multiple copies of the same document throughout the Site Collection, throwing up links to outdated versions of the same document in the Search results and causing confusion for the site visitors.
The problem was very real in SharePoint Classic, but with SharePoint Modern, Microsoft introduced the Link Content Type for Document Libraries, which meant that you could include Links to remote documents in your Library and even apply metadata to help organise those Links in the same way you would with actual documents.
![]() |
| Click image to enlarge. |
So, if we can get site editors to change their habits and use Link Content Types instead of multiple copies of files, everything will be just great? Well, kind of ...
I ran into a bit of a challenge when creating a Power Apps searchable Gallery for a document library that uses a lot of Link Content Types. While the documents would open readily from the Gallery, the Link Content Types just downloaded shortcut files to the PC's local Downloads folder. Not really the behaviour I was looking for.
So I went to Google to try to find how a Power Apps Gallery could launch a document from a Library Link Content Type. I think that search term captured all the key words. I found just one post in the Microsoft Power Apps Community site that tried to tackle the problem.
In that post, the first solution offered was to add "?csf=1&web=1" to the end of the Launch Expression, which sort of, kind of works. But it's a pretty ugly result.
![]() |
| Click image to enlarge. |
Your visitors would need to know to click on the tiny and obscure Open button at the top right of the screen. That wasn't going to work for me.
Then, right at the foot of that same post, there were some instructions for using an embedded Flow to extract the URL from a Library Link file. The explanation was lacking in detail, so I set about decyphering it to figure out how to make it work for me.
SET UP THE FLOW
Let's start with creating the in-App Flow. Click the ellipsis at the foot of the Power Apps left hand navigation and select Power Automate from the fly-out menu.
![]() |
| Click image to enlarge. |
Click Create new flow and select the Create from blank button. Name your Flow now (I called mine getURL). This is important because first time I tried this I didn't and adding the name after working on the Flow proved trickier than it needed to be.
![]() |
| Click image to enlarge. |
When the Flow opens, the first Action - Power Apps (V2) - is already there. Expand the panel and add the value for the Document Library we're going to call later. I've labelled it "FilePath", here. Not the best label - it probably should have been "DocLibrary" - but it really doesn't matter. The key info is the pathway to the Library, which I've put in as:
/DocsMNTraining/
![]() |
| Click image to enlarge. |
The next Action we need is the Get file content using path. We add the site address and then the output from the previous action. These will then be combined to render the full pathway to the Library Link in the Document Library.
![]() |
| Click image to enlarge. |
Finally, we need to gather together everything from the first two actions and write the output into a variable for the Power Apps Gallery to process. Add the Action Respond to a Power App or flow. I called the variable "urlValue" and set its value to:
last(split(base64ToString(outputs('Get_file_content_using_path')?['body']['$content']),'URL='))
You can do this by adding the above script to an expression.
Because the Get file content using path action extracts the Link file's content as Base64, we need to convert it to a string before the Power Apps Launch function can recognise it (no, I didn't know that either). Bear with me, all will become clear.
![]() |
| Click image to enlarge. |
I mentioned at the start of this piece that trying to launch a Library Link Content Type from a Power Apps Gallery caused a shortcut to be copied to my Downloads folder. So I opened one of them and took a peek inside. This is what I saw:
![]() |
| Click image to enlarge. |
You can see that the actual URL is preceded by "URL=", so our formula above is saying, "grab everything after "URL=" and convert it from Base64 to a text string.
So far, so good.
... AND BACK TO THE POWER APP
When setting up a SharePoint Document Library in a Power Apps Gallery in the past, I've just used an HtmlText box and put in a formula something like this:
Concatenate("<a href='https://xxxxx.sharepoint.com/sites/SiteName/",ThisItem.'Full Path',"' style='Text-Decoration:None;'><b>",ThisItem.Name,"</b></a>")
I use ThisItem.'Full Path' in preference to ThisItem.'File With Extension' because it makes for a cleaner link and the icon (which we'll get to later) is enough to tell visitors what kind of file to expect. And that works fine for "real" files. But with URL links, we have to trigger the Flow to process the link information, so a different approach is needed. And that's where the Launch function comes in.
The formula we need is something that will kickstart the Flow, extract the Link URL and then action it from Power Apps, so something like this:
Launch(getURL.Run(ThisItem.'Link to item').urlvalue)
What that does is fire up the Flow, which compiles the Link's URL from the value ThisItem.'Link to item', converts it back into a string and writes the value to the variable urlvalue. The formula then Launches the value in the urlvalue variable.
That's all fine and dandy for processing URL links stored in a SharePoint Library. But what about the actual files - PDFs .docx, etc? Well, we just need to combine the formula into an If statement and we should be good to go. Like this:
If(
Lower(Right(ThisItem.'File name with extension', 3)) = "url",
/* Item is a SharePoint .url file */
Launch(
getURL.Run(
ThisItem.'Link to item'
).urlvalue
),
/* Item is a normal file */
Launch(
ThisItem.'Link to item'
)
)
What we're saying here is ... if the last three characters on the right of the filename are "url", run the Flow. If not, just use the regular ThisItem.'Link to item' value. The "lower" is just a precaution in case the Link's suffix is ".URL" instead of ".url".
Then, we need to deploy the solution into the Gallery. My first thought was to just put in a Text box displaying the FileName, then add the above formula to the Text Box's OnSelect property. And that does work. But the problem is, there are no visual indicators that the Text Box is a link - no dynamic underline, no mouse rollover state, so not ideal. And there aren't any Cursor or OnHover properties in a Text Box.
After a bit of head-scratching I finally settled on a Button, making the fill transparent, adding an underline to the text. The cursor change on rollover is part of the default Button setup.
An optional extra I thought worthwhile was to also tackle the icon displayed next to the Library item. A quick Google will throw up the formula for extracting the Microsoft file icons and the PDF one. But there is no default icon for Library Links. So I made one. And because it's a custom icon, I stored it in the Site Assets library, then wrote an If statement for the Image box.
If(Lower(Right(ThisItem.'File name with extension',3)) = "url",
https://xxxxx.sharepoint.com/sites/SiteName/SiteAssets/Link.png,
https://res-1.cdn.office.net/files/fabric-cdn-prod_20220127.003/assets/item-types/32/ & Last(Split(ThisItem.'File name with extension',".")).Value & ".png"
)
That should be everything you need to know to get a Power Apps Gallery to display functional Link Content Types (from a SharePoint Library) alongside regular files.
![]() |
| Click image to enlarge. |
I hope this helps someone.









No comments:
Post a Comment