How to show the folder path of a file in library views

Introduction

This post looks at ways in which you can show the folder path of a file as a standalone column within a SharePoint document library view.

UPDATE: I’ve updated this post after some comments asking how to do this for modern SharePoint libraries. Click here for more.

Classic SharePoint

The scenario

A common request I get is:

How do I see what folders/ sub-folders my files are in at a glance

– all users everywhere

Out of the box, there aren’t any columns available that you could potentially leverage to display this information in a standard SharePoint 2010 library.

The solution

So, just by adding one value in SharePoint Designer, here’s how you do it:

  • Navigate to the library you wish to change, create a new view under Library Tools > Library > Create View
  • Choose the relevant format of your view, give your view a name and press OK
  • Open SharePoint Designer > Open the site > open the library you were just working in
  • In the Views pane > click to open the view you just created
In SharePoint Designer, clicking on the view name will open the view in edit mode
  • In the code editor window, scroll down until you see something like the following:
<ViewFields>
	<FieldRef Name="DocIcon"/>
	<FieldRef Name="LinkFilename"/>
	<FieldRef Name="Modified"/>
	<FieldRef Name="Editor"/>
</ViewFields>
  • Add the following field reference in between the opening <ViewFields> and closing </ViewFields>
  • Add the field reference in the display order you would like it to appear in the view
Add the field reference to the View Fields list
  • Press the Save icon to save your changes
  • Press the Preview button to see your view in action in the browser

Now you will notice there is a new column being displayed “Path”, that is showing us the full location of the file or folder in the libary. You’ll also notice that this path will display data when at the library root, or in any folders or sub-folders in the library.

Library root displaying a files path
File in sub-folder displaying relative location

Bonus

Taking this one step further, what if we wanted to show files of a certain type, then create a view that groups these files by their folder location? Guess what, that’s exactly what I did!

  • Navigate to your library > create a new view as before, this time base your new view off the one you just created
  • If you wish to only show files of a particular type, use the filter by settings (for example below is filtered to only shows Word documents)
  • Make sure “show all items without folders” is selected
  • Press OK
Filtering to only show word documents, also showing items without folders
  • Back in SharePoint Designer > Open up the view you just created
  • Scroll down until you see the opening <Query> tag and add the following beneath it:
<GroupBy Collapse="FALSE" GroupLimit="30">
	<FieldRef Name="FileDirRef"/>
</GroupBy>

Save and preview your view, it should now be grouping by the Path field:

I know this has proven really useful for my company, so hopefully this helps out someone else too 🙂


Modern SharePoint

The scenario

With Microsoft retiring SharePoint 2010 designer workflows, plus the movement away from SharePoint Designer in general, a few readers have asked for a solution that works with modern SharePoint.

When researching this I considered whether suggesting to use SharePoint Designer 2013, as the above solution would still work in SharePoint Online using SPD 2013. But, as Microsoft say themselves although SPD 2013 remains supported, it’s depreciated – so I decided to go in a different direction.

The below example walks you through how you can create a flow in Power Automate to update a file after it’s been created to have the folder path shown in the document library view:

The solution

For this solution you will need to have access to create Flows in Power Automate, as well as an existing Document Library created in SharePoint Online:

  • Navigate to the document library you wish to show the folder path for
  • Add a single line of text column to the document library > give it a name (I called mine FolderPath)
  • Under the ellipsis, press Automate > Power Automate > Create a flow
  • In Power Automate, either use an existing, relevant template or start from blank
  • The trigger action should be When a file is created (properties only)
  • Set the Site Address and Library Name where you want to add the folder path
  • Insert a new step > select Update file properties.
  • Set the following values for the update file properties step:
    • Site Address: same as previous step
    • Library Name: same as previous step
    • Id: ID
    • FolderPath: Folder path

NOTE: The FolderPath within the Update file properties step is the custom column we created earlier. The Folder path (highlighted in red) is dynamic content available within the step in the flow. The folder path dynamic content is the path to the folder the item is in, relative to the site address.

Ensure you select the system Folder path dynamic content to pull the right data into the custom FolderPath column.

Here’s the flow in it’s entirety:

At this point test and save your flow to make sure it is working as expected 🙂

Bonus #1 – turn your folder path column into a hyperlink column

So if like me you want to take this one step further, wouldn’t it be good if we could easily make our newly showing folder paths, actual hyperlinks to the folders? Well the good news is you can!

  • Navigate back to your document library > click on the FolderPath column > Format this column
  • Under Apply formatting to make sure FolderPath is selected
  • Paste the following JSON into the custom formatting box:
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "style": {
    "color": "blue",
    "font-weight": "bold"
  },
  "attributes": {
    "target": "_blank",
    "href": "='YOUR SHAREPOINT SITE URL' + @currentField"
  },
  "txtContent": "@currentField"
}

NOTE: for more information on turning field values into hyperlinks, check out this awesome sample from sp-dev-list-formatting.

  • Press Save
  • Your FolderPath column values should now be legitimate hyperlinks that click through to the relevant folders

Bonus #2 – update existing files in the document library

This was another suggestion from a reader with regards to how to update files that existed in the document library before the flow was created.

Running a flow manually for individual files

When I began to consider how to do this I started by looking at ways to manually start the flow.

It appears the only real way to do this is to create a new column that adds a button next to each file, that allows you to run the flow. I’m not really enamoured by this approach as it doesn’t seem ideal to have an extra column to run a flow showing on every file in your library. If this is something you would like to pursue then I would recommend this great article by WonderLaura who has the process of creating a button to trigger a flow covered!

Update our flow to update all files if folder path is empty

My solution to this problem was to update the flow we created earlier to get the properties for all files in the library, then add a condition that checks if the FolderPath column is empty, then if yes runs our flow as before.

  • First, I added a Get files (properties only) action which gets all the files from the source library
  • Then I added a new Condition action, which simply checks if the FolderPath column we created is equal to null. You will also notice a new Apply to each action will be created
  • I then moved the previous Apply to each action into the “If yes” condition
  • I left “If no” blank, as it is ok to leave a condition blank if you don’t want it to do anything

Here’s the updated flow in full, which changes highlighted in red:


18 thoughts on “How to show the folder path of a file in library views

  1. JudiNZ December 1, 2020 / 9:32 am

    (Sigh) I wish someone would post an answer to this problem in Modern SharePoint – we don’t have SharePoint Designer to fall back on any more 😦

    Like

    • Anthony December 1, 2020 / 9:45 am

      Hi @JudiNZ thanks for posting. It’s not something I’ve looked into as of yet but I’ll add it to the list!

      Like

      • tdalon (@tdalon) December 16, 2020 / 10:11 am

        yes. would be much appreciated if you could share a solution for SharePoint Online

        Like

      • Anthony December 16, 2020 / 8:49 pm

        @tdalon thanks for the feedback, I’ve got something I’m working on, but I’m working on a more robust solution so I’ll let you know when I have it!

        Like

    • Anthony December 17, 2020 / 6:32 pm

      @JUDINZ, @TDALON, just a heads up i’ve updated this post with a new solution for modern SharePoint 🙂

      Like

  2. Anthony December 21, 2020 / 11:40 am

    Another quick note to say I’ve added an additional bonus section to this with a way to update files that were in the library before creating the flow

    Like

  3. Greg January 11, 2021 / 12:41 pm

    Does not work for SPO:
    Insert a new step > select Update file properties. This will insert an Apply to each step and add Update file properties inside
    Make sure value is set as the output from the previous step

    Like

    • Anthony January 11, 2021 / 12:58 pm

      Hi Greg, what do you mean it does not work? Can you provide some more detail? That example above has worked well for me so I’m not sure why it wouldn’t for you

      Like

      • Greg January 13, 2021 / 8:54 am

        Hi Anthony,
        Thank you for your reply.
        I use your ‘Modern SharePoint’ section.
        «Insert a new step > select Update file properties. This will insert an Apply to each step and add Update file properties inside»
        This does not seem to apply to my SPO/Flow environment.
        When I create a new step and select ‘Update file properties’ the form requests the following information:
        * Site Address: https://…
        * Library Name: …
        * Id: ID
        After filling in the form above it won’t insert an ‘Apply to each step’ and add ‘Update file properties inside’.
        And the ‘Flow Checker’ issues the following ‘Update file properties’ warning:
        Actions in this flow may result in an infinite trigger loop. Please ensure you add appropriate conditional checks to prevent this flow from triggering itself.

        Like

  4. Anthony January 13, 2021 / 10:48 am

    @Greg, thanks for coming back with more detail. I can see what i’d done wrong, the initial flow is only for when new files are created and i’d used screenshots from the bonus #2 which has confused things.

    I’ve updated all the solution steps and screenshots that i’ve just tested to work for adding the folder path when files are created 🙂

    Thanks for the feedback, let me know how you get on!

    Like

  5. Alexander January 22, 2021 / 4:18 pm

    Dear Anthony, I got the first part(power apps) and everything working properly, when i want to update the old folders it gaves me the 429 – “Too many requests” error . Is there another way to do manually folder by foder? Because i’ve a lot of folders.

    thank you,
    Alexander

    Like

    • Anthony January 22, 2021 / 4:30 pm

      Hi Alexander, thanks for the comment. Have you followed by steps in bonus #2 above? Im not 100% but is that error related to looping limits in Power Automate? This seems to say so: https://powerusers.microsoft.com/t5/General-Power-Automate/429-Too-Many-Requests-Error/td-p/736159

      To do this manually I would create a similar flow that populates a folder path column, but also have another yes/no column that I would update when I want to add a folder path for existing.

      I would then use this validate what item I want to add the folder path too, and run the flow against just that item.

      Hope this helps!

      Like

  6. Alexander January 22, 2021 / 4:34 pm

    Hi Anthony, thank you for the immediate reply.

    The loop that i have is in the #2 bonus, i follower step by step but it gaves me looping error.

    it’s strange no?

    Alexander

    Like

    • Anthony January 22, 2021 / 4:43 pm

      Hi Alexander, I must admit I haven’t tried this approach at scale yet, my idea was to provide a modern solution for the my original post, but after feedback I’ve included some additional options!

      As I mentioned previous, I think you are hitting some of the license limitations in Power Automate by the sounds of your error.

      You could also tweak the existing flow to target specific folders which would also fix the error.

      Like

      • Alexander January 22, 2021 / 5:33 pm

        Dear Anthony,

        Following the procedure to update all file with path = null , in the flow checker i’ve this message ”
        Actions in this flow may result in an infinite trigger loop. Please ensure you add appropriate conditional checks to prevent this flow from triggering itself.” maybe i do something wrong? Because i tried in another Library with less folder and it worked.

        Thank you a lot.

        Regards,
        Alexander

        Like

      • Anthony January 22, 2021 / 5:50 pm

        Hi Alexander, so are you getting this error as well as “429 – too many requests” as well?

        It’s not something that I’ve observed in my tenant, and if the same flow works on another library that must been it’s a specific issue and not the flow itself.

        I’d suggest looking at filtering your library in the flow to reduce the amount of items it’s updating as mentioned above.

        You could also use a combination of versioning and an additional yes no column to whittle down the number of items in your query. I’m actually working on something that uses this method but haven’t written about it yet.

        Sorry I can’t help more,

        Kind regards,
        Anthony

        Like

  7. tdalon March 7, 2021 / 5:51 pm

    Have you tested the case if you move a file? Will it trigger the flow with the trigger condition file created? Because the file isn’t really created if moved.

    Like

    • Anthony March 7, 2021 / 5:55 pm

      Hi,

      The bonus #2 covers manually triggering the flow as like you say moving the file isn’t a create trigger.

      Thanks
      Anthony

      Like

Leave a Reply to Greg Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s