Show Path Column in SharePoint
By Anatoly Mironov
PnP.PowerShell is just the tool you need to show the Path column in a SharePoint document library view. Scroll down to see the script, or read on to learn more.
Do you still have folders in SharePoint? Well, you are not alone. Remember the old dream of relying on metadata only? Forget it! As a matter of fact, folders are still a popular way of organizing files in SharePoint. When not overused, they provide “metadata” by itself, metadata that works even in synced folders, in archive scenarios, works best with Teams etc.
The good part of SharePoint is that you can create flat views out of folder structures. It is a matter of simple editing a view.
A flat view makes it easier to find your files. A problem that arises, though, is that you don’t know in what folder a particular file is located, and as I mentioned above, file location is metadata itself. You want to know the location, to see in what teams channel it lies, or what other files there are in the same subfolder. You might even want to know the folder path to find it in a synced folder in OneDrive on your computer.
A colleague of mine asked me the other day: How can we show the folder path column in a flat view of a SharePoint document library?
What options do search engines provide
I searched for a solution, unfortunately, I found only these two, both from 2019:
Finding a better solution
Both alternatives are still doable, but hey, I don’t want to use SharePoint Designer, nor Power Automate, that requires an update of every single file in SharePoint Library. Some libraries are huge.
The SharePoint Designer alternative mentions the built-in column called
What if one could the Path column without hacking in SharePoint Designer. I looked in the settings of my document libraries.
There was no Path column. Neither it was available in the “Show/Hide columns” menu in a view.
This is unfortunate, this means an end user cannot show this column. But there should be this column behind the scenes, shoulnd it? I mean, every item in a list or a document library in SharePoint has its Path, it can be viewed in the information panel.
Well, if there is no way the Path as a column by editing a view, I decided to try PnP.PowerShell. It is not as end-user-friendly, but at least, it is better than the old SharePoint Designer (a.k.a. “SharePoint Destroyer”).
It actually works, one can add the Path column to a view. Here is a PowerShell script I came up with.
For this I need ListId and ViewId. The easiest way to get those is to copy the Edit View URL in the adress bar.
This short script will log in to the site, parse the List Id and the View Id, read the shown columns (
append the Path column (
FileDirRef field), and update the current view.
The script that shows the Path column
Some last words
To me it seems odd that the
Path column is not among the columns regular users can show in the web interface. This PnP.PowerShell script can help you as an admin to show the Path when users need it. Is there some other solutions for that? Please share your thoughts.