Sometimes, when working in a SharePoint Document Library, you want to see the Folder Path for each document. This is especially useful if you are working in a Library View which is showing all documents without Folders.
The problem is there is no out of the box way to add the Path property to a standard SharePoint view. Bah.
But luckily, there's a very simple PnP script you can use to do this! Simply replace the tokens (highlighted yellow) in the script below with your values, run the script and the Folder Path for each document will be added to the specified View.
$site = "https://xxx.sharepoint.com/sites/Finance"
Connect-PnPOnline $site -Interactive
$viewId = "fbe2cxxx-6xxx-xx94-bxxx-545ccda40xxx"
$listId = "4b8bdxxx-9xxx-xxa0-axxx-61c40442fxxx"
$view = Get-PnPview -List $listId -Identity $viewId
$viewFields = @()
$view.ViewFields | ForEach-Object {
$viewFields += $_
}
$viewFields += "Path"
Set-PnPView -List $listId -Identity $viewId -Fields $viewFields
You can see the results of this little script below: it adds the Folder Path to each documents to the specified view; this allows you to filter, order, group by etc on the Folder Path.
Handy!
Comments