Skip to main content

Converting a Folder to a Document Set

·4 mins

Document Sets are often referred to as “folders on steroids” in SharePoint, as they provide a way to group related documents together, while also providing additional metadata and functionality.

However, there may be situations where you have an existing folder that you want to convert into a Document Set to take advantage of these features.

While SharePoint does not provide a direct way to convert a folder into a Document Set, it is indeed possible to achieve.

Prerequisites

First we must ensure that we have Document Sets enabled, and a content type for Document Sets created.

PnP PowerShell

You’ll need to have PnP PowerShell installed and be able to connect to your SharePoint site where the folder resides.

For more information on installing and setting up PnP PowerShell, refer to the official documentation.

Enabling Document Sets

To enable Document Sets in your SharePoint site, follow these steps:

  1. Go to Site Settings on your SharePoint site.
  2. Navigate to “Site Collection Features”
  3. Activate the “Document Sets” feature.

Enabling Document Sets Feature

Creating a Document Set Content Type

  1. Go back to Site Settings on your SharePoint site.
  2. Press “Site content types”
  3. Create a new content type by pressing “Create”
  4. Name it appropriately, e.g., “My Document Set”
  5. Make it inherit from “Document Set” as the parent content type. (it’s under the “Document Set Content Types” group)
  6. Press OK to create the content type.
  7. (Optional) Add any additional columns or metadata to the Document Set content type as needed.

Creating a Document Set Content Type

Adding the Document Set Content Type to a Library

Next, we need to add the newly created Document Set content type to the document library where the folder resides.

  1. Navigate to the document library containing the folder you want to convert.
  2. Go to Library Settings.
  3. Under “Advanced settings”, ensure that “Allow management of content types” is set to “Yes”.
  4. Back in the Library Settings, under “Content Types”, click “Add from existing site content types”.
  5. Select the Document Set content type you created earlier and add it to the library.
  6. Press OK to save the changes.

Converting the Folder to a Document Set

Now that we have the Document Set content type added to the library, we can proceed to convert the folder.

First we need to grab the content type ID of the Document Set content type we created earlier, this is where things get a bit ’tricky'

Jump back into the library settings, and under “Content Types”, click on the Document Set content type you created earlier.

In the URL, you’ll see a string piece of text after “ctype=” - it starts with 0x0120D5 - copy this entire string, as this is the content type ID we need for the conversion.

Mine was 0x0120D5200015E586766B0CF54B87B393D434B58BE6 - but yours will be different, so make sure you copy it correctly.

With the content type ID copied, we can get to converting the folder, I like to use PnP PowerShell for this, as it makes things quite straightforward.

# Variables
$siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
$listName = "Documents" # Change to your document library name
$docSetContentTypeId = "0x0120D5200015E586766B0CF54B87B393D434B58BE6" # Change to your Document Set content type ID

Connect-PnPOnline -Url $siteUrl 

$list = Get-PnPList $listName -Includes RootFolder.Folders

# Get all folders in the library
$folders = $list.RootFolder.Folders | Where-Object { 
    $_.Name -ne "Forms" # Exclude system folders
}

# Loop through each folder
foreach ($folder in $folders) {
    Write-Host "Processing folder: $($folder.Name)" -ForegroundColor Cyan
    
    # Get the list item ID from the folder's ListItemAllFields
    $folderItem = Get-PnPProperty -ClientObject $folder -Property ListItemAllFields
    
    if ($folderItem) {
        $currentContentTypeId = $folderItem["ContentTypeId"]
        
        # Check if it's already a Document Set (Content Type ID starts with 0x0120D5)
        if ($currentContentTypeId -notlike "0x0120D5*") {
            Write-Host "  Converting to Document Set..." -ForegroundColor Yellow
            
            # Set the content type to Document Set
            Set-PnPListItem -List $listName -Identity $folderItem.Id -Values @{
                "ContentTypeId" = $docSetContentTypeId
            } -UpdateType "Update"
            
            Write-Host "  Successfully converted!" -ForegroundColor Green
        }
        else {
            Write-Host "  Already a Document Set, skipping." -ForegroundColor Gray
        }
    }
}

Write-Host "`nConversion complete!" -ForegroundColor Green

TL;DR

By changing the content type ID of the folder to that of a Document Set, SharePoint treats it as a Document Set, allowing you to leverage all the features and benefits that come with Document Sets.