Using documensets is a fantastic way of organising your documents, benefits of documentsets include:
- Folder-like behavior,
- metadata filtering towards you documentsets,
- different default views for the library and the contents of a documentset,
- the optional metadata syncing from the documentset towards the documents contained within
This post is not about setting up the documentset in a library, but what we do want to do here, is to create a column that shows in which documentset a file is stored…
Now why would that be useful?
Imagine a library containing documentsets with an additional view which shows all the recent documents stored within the documentsets. So not the recent documentsets, but only the recent files.
![](https://exceltrainer.be/wp-content/uploads/2022/04/675-OpenDocumentset-ani.gif)
Create the Recent documents-view
You can easily do this using the classic experience for changing views.
Let’s assume we have a library with a documentset content type called “Project Folder”.
- Select the current view and choose Save view as
- Enter a name that would make sense, like, “Recent Documents”
- Click on ethe view and choose Edit current view
- Go to the Folders-section and select Show all items without folders
Although this will start showing the documents, you still get to see the documentsets too.
So, in order the hide the documentsets: - Go to the Filter-section and select: Content Type is not equal to Project Folder
Where Project Folder is the name of the documentset content type
Create the Project-column
Now let’s make sure we can see to which project every document belongs.
We therefore need to create a new column that is going to contain the format that allows us to see the documentset-name.
It is important to note that we are only applying a column format that shows the documentset-name, we are not going to fill the column with any data because that should involve some triggered-scripting.
- Go to the “Recent Documents”-view
- Click on Add column, and select Single line of text
- Enter a useful name for this column, for example: “Project”
- Click on More options and deactivate “Add to all content types”
By doing so, this column will not show up in any properties-form. - Now the column is created, we can apply the format that will generate the name and the link.
Click on the column-header and select Column settings > Format this column - Click on advanced and copy-paste the code below
- Click on Save to save and close the column format.
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "a", "txtContent": "=substring(substring([$FileRef], 1, lastIndexOf([$FileRef],'/')),lastIndexOf(substring([$FileRef], 1, lastIndexOf([$FileRef],'/')),'/')+1,1000)", "attributes": { "href": "=replace([$FileRef], '/'+[$FileLeafRef],'') + '/'" } }
Conclusion
Documentsets are great, and with some extra attention we can make them even more user-friendly.
Update: I have updated the code based on a tip from The Chris Kent | Quick Fixes, Workarounds, and Other Neat Tricks