Forum Discussion
Displaying DocLib File URL Path in Column
- Jul 18, 2023
Hi KevBel,
you could apply the following json formatting to your "Path" column{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=[$FileRef]" }
You will get a view like thisIf you don't want the path to your document library to be displayed ("/sites/MyAppPage/CopyLib/" in my example), then use this json
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=replace([$FileRef],'/sites/MyAppPage/CopyLib/','')" }
This will look like this
Best Regards,
Sven
Hi KevBel,
you could apply the following json formatting to your "Path" column
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=[$FileRef]"
}
You will get a view like this
If you don't want the path to your document library to be displayed ("/sites/MyAppPage/CopyLib/" in my example), then use this json
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=replace([$FileRef],'/sites/MyAppPage/CopyLib/','')"
}
This will look like this
Best Regards,
Sven
- botsauceMay 28, 2025Copper Contributor
Hi SvenSieverding,
This solution is great, but I can’t copy the text that is displayed here nor does it appear in the details (as it is just formatting, I guess?). Is there a way to have the displayed text copied to the clipboard via a json button?
- Markus HanischJul 17, 2025Brass Contributor
You can create a Power Automate flow that outputs the values of the internal / hidden Site column FileDirRef (FolderPath) or FileRef (FilePath) in a custom column.
By the way, if you would like to output solely the folder path that doesn't contain the file name in it, use this custom column formatting -- replacing <sitename> and <libraryname> accordingly FIRST:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=substring(replace([$FileRef], '/sites/<sitename>/<libraryname>/', ''), 0, lastIndexOf(replace([$FileRef], '/sites/<sitename>/<libraryname>/', ''), '/'))" }
Example:
[$FileRef] = /sites/MyAppPage/CopyLib/HR/Policies/Leave.docx
Output:
HR/Policies
- lpeve01Jul 17, 2024Copper ContributorHello Sven! Thanks so much. it works! I went through the docs but I could not find much about what attributes are available with the `@<attribute_name>`. Can you share some links?
- DavidH2210Jul 10, 2024Copper Contributor
Hi Sven this works for me, but I would like to export the data, and push the url into another system. when I export it the field is blank, I have read that I need a calculated field to export it, any ideas on how you get the same output with a calculated field?
EDIT: NVM I was Able to solve this via Power Automate, thank you on getting me on the right path
- OluAKIN007Jul 20, 2024Copper Contributor
Hello there. Good to know that you have it figured out.
I am in the same space and kind of struggling - the path now displays on the document library but blank in Excel when I download it in a query. Could you please point me in the right direction on this?
- DavidH2210Jul 22, 2024Copper Contributor
I ended up abandoning this route and formatted it with power automate, which is free.
I have mine set to
1) Trigger: when a file is created
2) Action: Get File metadata; in File identifier section DO NOT USE ID use the Identifier field
3)Action: Compose; in the inputs select the fx lil icon and put this in it replace(outputs('Get_file_metadata')?['body/Path'],' ','%20') this will remove the spaces from the path so its URL ready
4) Action: update file properties; for ID use body/itemid
then in your link filed place https://YOURURL.sharepoint.com/sites/YOUR_SITE
then use the output from the compose step, you will have to tweak this but this will save you a few days of head aches, this will auto create the link when a file is uploaded.NOTE: if you have # or any other characters that may mess us the URL you will need to take the output form the first compose and compose again to replace "#" with %23 and if you find other like that you will need to repeat the compose from the compose steps.
- KevBelJul 18, 2023Copper ContributorThat second example is perfect for my needs - thank you!
Would there be a way to remove the file name from that path view as well? Seeing the output, it looks a bit redundant to show the file name again since it already exists in the NAME column.- SvenSieverdingJul 18, 2023Bronze Contributor
Hi KevBel,
in the SharePoint data model, the NAME column is called FileLeafRef. We can replace that value with an empty string like this{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=replace(replace([$FileRef],'/sites/MyAppPage/CopyLib/',''),[$FileLeafRef],'')" }
Best Regards,
Sven