Forum Discussion
KevBel
Jul 18, 2023Copper Contributor
Displaying DocLib File URL Path in Column
Good day,
Using SharePoint Online (modern) and set up a new document library called DOCLIB1. There are two folders in the library called FOLDER1 and FOLDER2. FILE1.TXT and FILE2.TXT are located within FOLDER1 (and are displayed by those names in the SharePoint default "NAME" column). There is also a FILE2.TXT (same name but different content) in FOLDER2.
Searching the DocLib for anything called "FILE2", I see two results, but cannot tell where the files are located (cannot tell which is which).
I created a new column called PATH, with a Type of "Single line of text". Can I display a file path in this new column to see something like "FOLDER1/FILE2.TXT" for the first search result returned, and "FOLDER2/FILE2.TXT" for the next?
Thanks!
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
- danieljarquinCopper Contributor
When managing a document library, particularly within a content management system or collaboration platform, it's often essential to display the URL paths of files within a column for easier access and reference. For users of the MomixAPK platform, which provides a streamlined way to manage and share content, this feature can significantly enhance productivity and collaboration. Here’s a detailed guide on how to display DocLib file URL paths in a column on MomixAPK.
Why Display URL Paths?
Displaying URL paths in a column within MomixAPK offers several advantages:
Easy Access: Users can quickly click on the URLs to access documents directly.
Improved Navigation: Provides a clear reference to the location of files - Anatoly MironovBrass ContributorThere is a built-in column called Path that shows the Path nicely formatted and every folder and subfolder is clickable. The Path is relative to the sharepoint site (web). All you need is to add this "Path" column to a view programmatically (PnP, Rest API), I have an example on m blog post: https://chuvash.eu/2023/show-path-column/
- SvenSieverdingBronze Contributor
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- lpeve01Copper 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?
- DavidH2210Copper 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
- OluAKIN007Copper 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?
- KevBelCopper 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.- SvenSieverdingBronze 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
KevBel You can run a Power automate flow on file creation / update (as per your requirements) and then update the new PATH column from your flow OR use JSON formatting for showing the file path. However, I am not sure if JSON formatting will work in search results page or not (I have to test it from my end).
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.