How to Fix "File Name or Path Too Long" and Invalid Character Sync Errors in SharePoint and OneDrive
Published:
Last updated: 2026-10-29
SharePoint and OneDrive allow a decoded path of up to 400 characters, but Windows apps hit trouble far sooner: Office desktop apps stop at about 256 characters and File Explorer at 260. Shorten the folder names near the top of the path, or move deep folders higher. To find every long path at once, run an item inventory and sort by path length, either with PnP PowerShell or with the free SharePoint Essentials Toolkit.
Why does sync say the file name or path is too long?
There are several limits, and the one you hit depends on where the file is opened. Microsoft lists them in What are the file path length limits?:
Where | Limit | What counts |
|---|---|---|
SharePoint and OneDrive in the cloud | 400 characters | The decoded path from the site to the file, including the file name |
OneDrive sync app on Windows | 520 characters | The local path, up to 400, plus the OneDrive root folder |
Office desktop apps on Windows | About 256 characters | The full local path when you open the file |
File Explorer | 260 characters | The full local path; Explorer doesn't use the Windows long-path setting |
The local path is longer than the SharePoint path. A synced library lands in a folder such as C:\Users\jsmith\Contoso\Projects - Documents\, and every folder below it adds to the count. A path that is fine in the browser can be too long for Word on the same PC.
A real example from our test site: a file whose SharePoint path is 336 characters comes to about 350 characters once synced to a typical local folder. That is well inside the 400-character cloud limit and far past the 256 that Word desktop can open. Uploading a new version of it through the SharePoint REST API also failed with "The length of the URL for this request exceeds the configured maxUrlLength value", well before the 400-character limit.
Invalid characters and names
Sync also stops on names SharePoint doesn't allow. From Microsoft's Restrictions and limitations in OneDrive and SharePoint:
These characters aren't allowed in file or folder names:
" * : < > ? / \ |Names can't start or end with a space, or end with a period.
These names aren't allowed:
.lock,CON,PRN,AUX,NUL,COM0-COM9,LPT0-LPT9,_vti_,desktop.ini, and any name starting with~$.formsisn't allowed as a folder name at the root of a library.
Windows allows some of these, so they turn up when people sync folders from a file share or a Mac.
Option 1: Fix path and name errors with built-in tools
Select the OneDrive cloud icon in the Windows taskbar, then View sync problems. Each problem names the file and the reason.
To fix a long path, rename a folder near the top of the path in SharePoint. One shorter folder name shortens every path below it. "2026-014 Riverside Medical Center Expansion - Phase 2 Outpatient Wing" can become "2026-014 RMC Phase 2".
Or move a deep folder up a level or two. In the library, select the folder, then Move to.
To fix a name, rename the file in SharePoint or in the sync folder. Sync picks up the change and retries.
If people sync from deep inside a library, have them use Add shortcut to My files on the folder they need instead. The local path is then shorter.
What to know:
The browser can't list files by path length. You find long paths one sync error at a time.
Renaming a top folder breaks links people saved to files below it. Folder links in Teams and bookmarks need updating.
Windows has a long-path setting, but File Explorer and Office desktop apps don't use it, so turning it on doesn't fix this.
Option 2: Find long paths and invalid names with PowerShell
This PnP PowerShell script lists every file and folder in a site whose path is close to the limit or whose name SharePoint and sync reject. It changes nothing. It needs PnP PowerShell 2.x or later and your own Entra ID app registration.
# Report long paths and invalid names in every document library on a site (read-only)
$ClientId = "<your-app-id>"
$SiteUrl = "https://contoso.sharepoint.com/sites/Projects"
$WarnAt = 300 # SharePoint allows 400; synced and Office paths fail sooner
$OutFile = "C:\Temp\long-paths.csv"
Connect-PnPOnline -Url $SiteUrl -Interactive -ClientId $ClientId
$reserved = '^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9]|\.lock|desktop\.ini)