I'm working on enhancing metadata in our SharePoint online (O365) environment. Since a portion of my user base is used to foldering (explorer style), I've started using default column values to automatically set values on any files added to that specific folder (we have content organized categorically by folder currently). An example is our HR documents library - we have separate folders for recruiting, payroll, personnel files, etc. that automatically categorize files added to that folder with the same categories (recruiting, payroll, personnel, etc.). This supports both "search" and "click" users and makes adoption WAY easier while getting important metadata.

I want to implement this in a larger, more dynamic fashion, so manually setting default column values on each folder is not going to be scalable.

How can I reference the top level folder within the library (or even the current folder) for each newly added file and populate the "category" field for that new file with that folder name? I can do some very basic C# or Java code copy/paste, but bonus points for non-coding solutions =)

  • Which kind of SPField is your "category" field? Aug 6, 2018 at 13:10
  • It's currently a string (short text) for testing/proof of concept but will end up as either a lookup from a list or a multiselect to standardize entries. Aug 7, 2018 at 14:08

2 Answers 2


Have you checked out Document Sets? These behave like folders when you open them in explorer, but give you the ability to set metadata. And the best part, you can configure your documents to inherit the metadata of your Document Set.


I use this quite often and always set it up like this (mostly through code by the way)

  1. Create site columns
  2. Create a document set content type and add the site columns from 1
  3. Create a document content type and add the site columns from 1
  4. Configure the document set to make the documents inherit the metadata from the document set
  5. Remove the default document content type from the list of available content types for that document set.
  • 1
    Hi Martijn - We have used document sets before; we're actually using them for the exact functionality in our 2010 environment (we're in the process of migrating). We're looking to update the data model to make searching available at the file level instead of the doc set level. That's a really creative way of managing the data - I'll definitely look more into that method! Thanks! The other variable I didn't mention was that we're using the Dyanmics CRM 2016 OOB connector to build the folders, so I'll have to look into level of effort to create doc sets rather than folders from CRM. Aug 7, 2018 at 14:07
  • I've just delivered a custom integration with CRM using document sets. I really don't like the OOB integration. I've posted a similar solution a while ago on my blog: oak3.org/azure/…
    – Oak3
    Aug 7, 2018 at 14:24

You could create a workflow for your library, when a file got uploaded, check folder name check here, based on folder name, update file item field value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.