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

Find out how to quickly and easily display the folder path of all files in a SharePoint library without writing code…

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:


33 responses to “How to show the folder path of a file in library views”

  1. This page just helped me in 2024 figure out a way to add the Path / FileDirRef column to a View! Thanks!

    If you’re reading this comment, consider upvoting this MS Feedback item asking for a way to do so without SharePoint Designer 2013? https://feedbackportal.microsoft.com/feedback/idea/d5775a73-c6d1-ee11-92be-000d3a0e6cad

    Also, if you do need to use SharePoint Designer w/ Modern Authentication, check this article for instructions (that for me required a registry edit): https://techcommunity.microsoft.com/t5/microsoft-sharepoint-blog/sharepoint-designer-and-modern-authentication/ba-p/382774

  2. Using the following href will allow creation of a reusable site column. I called mine “Container” so
    that it could be used generically with both folders and document sets. Also, if desired, you can shorten txtContext by removing the library name and trailing slash.
    “href”: “=@currentWeb + ‘/’ + @currentField”
    “txtContent”: “=substring(‘@currentField’, 1+indexOf(‘@currentField’,’/’), lastIndexOf(‘@currentField’,’/’))”

  3. Hi Joseph, I’ve just double-checked my original example and I had two levels of folder within the document library. Is that what you mean by nested folders?

  4. It’s only updating the field for folders, not actual files – any idea why this might be?

    1. Hi, thanks for the comment. I’m not sure what you mean, my example updates the folder path for files, not just folders

      1. That’s what I’d expect as well, but for some reasons the new column is left blank for the files. Let me try this on a site I created instead of my work site, it might be a permissions issue (even though I have full editing rights).
        I wonder if there’s any way to see a break point or why a file didn’t get affected…

        Also thank you again for this guide and the quick response!

      2. The files get updated too when I turn off nested folders, so it looks like nested folders as a “Yes” doesn’t work / doesn’t propagate as it should.

  5. I tried uploading 20000 files and the SharePoint crashed, what now?

    1. Hi, what do you mean SharePoint crashed exactly? I’m not sure what this has to do in relation to my post

  6. This is fantastic and has been so helpful, thanks!

    I do have a problem with the format as URL part, if you have any ideas.

    Anything I add in attributes/href is just being appended to the current page path, which is annoying!

    1. Hi Phil, thanks for the comment – glad to see this post is still proving useful! So in my example im adding the sharepoint site url before the folder path itself to build the full url. What is in your syntax is it like this: “href”: “=’YOUR SHAREPOINT SITE URL’ + @currentField”?

  7. I received an error that I need to enter a valid uri in the FTP Site field. Do you have any advice on what they are looking for?

    1. Hi Ashley, I’m not sure what you mean by the FTP site field, that’s not in my walkthrough I don’t think.

      Thanks
      Anthony

      1. It is not a field in your walkthrough, but one I am receiving an error message for leaving blank.
        OpenApiOperationParameterTypeConversionFailed. The ‘inputs.parameters’ of workflow operation ‘Update_file_properties’ of type ‘OpenApiConnection’ is not valid. Error details: Input parameter ‘item/FTPSite’ is required to be of type ‘String/uri’.

      2. It’s not something I’ve come across myself, I’m using the same update file properties action and I don’t get that error.

        I take it “FTPSite” is a column? Is it set up as a hyperlink column? I’ve found this which sounds like the same issue you have: https://powerusers.microsoft.com/t5/Process-Advisor/How-to-fix-the-following-error/td-p/813953

  8. 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.

    1. Hi,

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

      Thanks
      Anthony

  9. 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

    1. 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.

      1. 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

      2. 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

  10. 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

    1. 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!

  11. @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!

  12. 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

    1. 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

      1. 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.

  13. 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

  14. (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 😦

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

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

      2. @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!

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

Leave a Reply to AnthonyCancel reply

Recent posts

Discover more from SharePoint Stuff

Subscribe now to keep reading and get access to the full archive.

Continue reading