Forum Discussion
How to show folder path for documents in a flat SharePoint library view
I have a document library with a multi-level folder structure that is somewhat complex. I created a view that removes folders and displays all documents in a flat structure (no folders shown).
How can I display or indicate the folder path (or location) for each document in this flat view, so users can understand where each file is stored within the original folder hierarchy?
Step 1: Create a new column
Go to Library Settings
Click Create Column
Type: Single line of text
Name: Folder Path (or anything)
Step 2: Apply JSON formatting
I am mostly using this JSON in all my projects. The path is hyperlinked and opens the folder in a new tab.{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "a", "attributes": { "href": "=substring([$FileRef],0,lastIndexOf([$FileRef],'/'))", "target": "_blank" }, "style": { "display": "flex", "align-items": "center", "background-color": "#f2f2eb", "border-left": "3px solid #cceced", "border-right": "3px solid #cceced", "padding": "2px 8px", "max-width": "100%", "height": "22px", "text-decoration": "none" }, "children": [ { "elmType": "span", "attributes": { "iconName": "OpenFolderHorizontal" }, "style": { "font-size": "16px", "color": "#003366", "margin-right": "5px", "flex-shrink": "0" } }, { "elmType": "span", "txtContent": "=replace(substring([$FileRef],0,lastIndexOf([$FileRef],'/')),'/sites/YOURSITE/Shared Documents/','')", "style": { "color": "#003366", "white-space": "nowrap", "overflow": "hidden", "text-overflow": "ellipsis", "max-width": "100%" } } ] }Replace this:
/sites/YOURSITE With your actual site path
I am using /sites/YOURSITE with the actual site path so the site name does not show in the path. This makes it easier for users to read.
If you want, you can also include the library name in the path. If you have many nested folders, removing the site part gives more space to clearly show the folder structure.
Step 3: Include this column in flat structure-views
If my post solved your issue or answered your query, please mark it as a Solution and give it a Like.
2 Replies
- virendrakSteel Contributor
Step 1: Create a new column
Go to Library Settings
Click Create Column
Type: Single line of text
Name: Folder Path (or anything)
Step 2: Apply JSON formatting
I am mostly using this JSON in all my projects. The path is hyperlinked and opens the folder in a new tab.{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "a", "attributes": { "href": "=substring([$FileRef],0,lastIndexOf([$FileRef],'/'))", "target": "_blank" }, "style": { "display": "flex", "align-items": "center", "background-color": "#f2f2eb", "border-left": "3px solid #cceced", "border-right": "3px solid #cceced", "padding": "2px 8px", "max-width": "100%", "height": "22px", "text-decoration": "none" }, "children": [ { "elmType": "span", "attributes": { "iconName": "OpenFolderHorizontal" }, "style": { "font-size": "16px", "color": "#003366", "margin-right": "5px", "flex-shrink": "0" } }, { "elmType": "span", "txtContent": "=replace(substring([$FileRef],0,lastIndexOf([$FileRef],'/')),'/sites/YOURSITE/Shared Documents/','')", "style": { "color": "#003366", "white-space": "nowrap", "overflow": "hidden", "text-overflow": "ellipsis", "max-width": "100%" } } ] }Replace this:
/sites/YOURSITE With your actual site path
I am using /sites/YOURSITE with the actual site path so the site name does not show in the path. This makes it easier for users to read.
If you want, you can also include the library name in the path. If you have many nested folders, removing the site part gives more space to clearly show the folder structure.
Step 3: Include this column in flat structure-views
If my post solved your issue or answered your query, please mark it as a Solution and give it a Like.
- EvanSP_555Brass Contributor
Thank you for the solution.