Update: I added a small script below to create a folder structure in a tenant so that you can test the new limit

Yesterday, Microsoft announced another small but great change to SharePoint Online and OneDrive: in previous versions of SharePoint you were limited to a maximum path length of 256 characters. This meant that if you had a very deep folder structure, potentially also with long file or folder names, you would at some point hit that limit and not be able to add any files/folders which would have a total path length of more than 256 characters. In SharePoint Online and OneDrive, this limit has now been increased to 400!

While a lot of people advise to move away from folders and towards a metadata-driven architecture, the reality is that the majority of a company’s information is organised with folders. Lots and lots of folders. Which, on your local hard drive or a shared drive, are often organised in a tree-like structure with multiple levels, and thus also potentially exceeding the path length limit.

But, this may cause problems during migrations to SharePoint Online. I’ve seen it during a couple of projects I did recently which migrated content to SharePoint Online – and while more than 99.9% of the content was able to move without issues, there were still some files that were impacted by this limit. Path length in the source environment may have been still below the limit, but as the content was restructured (e.g. it was moved to another subsite with a longer path), the overall length increased and the content could not get migrated. The only option was to reduce the path length, for example by reorganising the folder structure, or renaming files/folders.

Coming back to SharePoint Online and OneDrive: this new limit should be available to everyone straight away! I wrote a small PowerShell script to create a simple folder hierarchy, and was able to go beyond the 256 characters and hit the 400 limit:

And here’s the error shown when you try to create a folder in the UI:

One thing I noticed, however, is that the explanation given by Microsoft on which parts of the file URL are actually part of the path seems to be not quite correct. In my test setup, I managed to successfully create a path of 430 characters, 431 failed. After a quick check I saw that my protocal and server name came to a total of 30 characters – so, I asked on the official announcement for a clarification. But either way, it should be quite rare to run into the 400 character limit, and it’s great to see that Microsoft is finally addressing an issue that has been around for a long period of time.

Update: Here is the script that I used. It will run into a limit and you’ll get an error similar to the screenshot further above. Also, please note that the script creates a library, but does not delete it.

#replace with your own demo site in your own tenant
$url = "https://mytenant.sharepoint.com/sites/demo"
#modify the following two variables if required
$libName = "MaxPathTest"
$folderName = "012345678901234567890123456789"

$cred = Get-Credential
write-host "Connecting to $($url)"
Connect-PnPOnline -Url $url -Credentials $cred
write-host "Creating library $($libName)"
New-PnPList -Title $libName -Template DocumentLibrary

$folder = $libName
do {
	$pathLength = $url.Length + 1 + $folder.Length + 1 + $folderName.Length
	write-host "Trying path length of $($pathLength)"
	Add-PnPFolder -Name $folderName -Folder $folder
	$folder = $folder+"/"+$folderName	
} while ($pathLength -le 500)

10 thoughts on “Increased Path Length for Files in SharePoint Online and OneDrive”

    1. Hi, I think it’s the same details as in the techcommunity announcement. Still unsure about the actual definition of what goes into the path. But as mentioned, 400 is quite a lot of characters, should make it a very rare occurrence to run into this limit

Leave a Reply

Your email address will not be published. Required fields are marked *