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 ~$.

  • forms isn'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

  1. Select the OneDrive cloud icon in the Windows taskbar, then View sync problems. Each problem names the file and the reason.

  2. 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".

  3. Or move a deep folder up a level or two. In the library, select the folder, then Move to.

  4. To fix a name, rename the file in SharePoint or in the sync folder. Sync picks up the change and retries.

  5. 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)
    
    
    
    
    
  


$results  = foreach ($list in Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 -and -not $_.Hidden }) {
    Get-PnPListItem -List $list -PageSize 2000 -Fields "FileRef", "FileLeafRef" | ForEach-Object {
        $path = $_.FieldValues.FileRef.TrimStart('/')          # decoded, server-relative
        $name = $_.FieldValues.FileLeafRef
        $issues = @()
        if ($path.Length -gt $WarnAt)              { $issues += "Path $($path.Length) chars" }
        if ($name -match '["*:<>?/\\|]')           { $issues += "Invalid character" }
        if ($name -match $reserved -or $name -like '~$*' -or $name -like '*_vti_*') { $issues += "Reserved name" }
        if ($name -ne $name.Trim() -or $name.EndsWith('.')) { $issues += "Leading/trailing space or period" }
        if ($issues) {
            [pscustomobject]@{ Library = $list.Title; Length = $path.Length; Issues = $issues -join '; '; Path = $path }
        }
    }
}
$results | Sort-Object Length -Descending | Export-Csv $OutFile -NoTypeInformation
"$($results.Count) items need attention. Saved to $OutFile"

To check a PC before the sync app does, scan the local folder. This finds paths that File Explorer and Office will struggle with:

# Local paths over 250 characters in a OneDrive or synced library folder (read-only)
$Root = "$env:USERPROFILE\Contoso"
Get-ChildItem -LiteralPath $Root -Recurse -Force -ErrorAction SilentlyContinue |
    Where-Object { $_.FullName.Length -gt 250 } |
    Select-Object @{ n = 'Length'; e = { $_.FullName.Length } }, FullName |
    Sort-Object Length -Descending

What to know:

  • FileRef is decoded and server-relative, which is what the 400-character limit counts.

  • Large libraries take a while, and the script runs site by site.

  • Characters SharePoint already blocked never reach it, so the invalid-name check matters most for folders about to be uploaded or synced in.

Option 3: Find every long path with SharePoint Essentials Toolkit

The toolkit's item inventory reports every file and folder with its full URL, folder depth and path length, across as many sites as you pick. We ran it on a test site, Architecture-Knowledge-Base, where a project folder six levels deep holds drawings, minutes and specifications.

1. Run an item inventory

Open Tasks, choose Inventory, and pick Get inventory of items, files, folders, pages.

Inventory tasks in SharePoint Essentials Toolkit: inventory of sites and lists, items files folders and pages, labels and metadata, users

The Inventory area. The item inventory is the second task.

Pick the sites, check the summary, and select Run Now. The report only reads.

Item inventory summary before running: one site, every list and library

The summary confirms the scope before the report runs.

On our site it took under a minute for 132 items in 8 lists.

2. Sort by path length

Switch the view to All Items, show the Item Url Path Length and Folder Depth columns, and sort by path length, longest first.

Item inventory report views: All Items, Grouped By List, No Checked in Version, Sizes By List and Folder

The report's views. All Items gives one flat list to sort.

SharePoint item inventory sorted by Item Url Path Length: files at 386, 371 and 344 characters, six folders deep

The longest paths on the site, six folders deep. Anything above about 285 here comes out longer than 260 characters once synced to a typical local folder.

Item Url Path Length counts the whole URL, including https:// and your tenant name. Subtract the length of your tenant address (https://contoso.sharepoint.com is 30 characters) to get the path SharePoint measures against 400.

3. Fix the worst folders first

Long paths cluster. On our site the six longest items all sat below one folder, "Superseded Drawing Sets and Review Comments - Reference Only". Shortening that one name, and the project folder above it, brings every file under it well below the sync limits. Select Export to send the list to Excel for the people who own the folders.

Before you move or copy a whole library, run Check before you copy in the Copy area. It flags paths over 400 characters, names with invalid characters, reserved names, files over 250 GB and checked-out files, so nothing fails halfway through.

Community Edition is free on up to 20 sites, and the item inventory has no item limit on those sites.

For more ways to use the same report, see the SharePoint inventory report guide. If sync is stuck rather than showing errors, see OneDrive sync stuck on processing changes.

Frequently asked questions

What is the maximum path length in SharePoint Online?

The decoded path, from the site through every folder to the file name, can be up to 400 characters in SharePoint and OneDrive. Windows apps have lower limits: Office desktop apps about 256 characters and File Explorer 260, measured on the local synced path, which is usually longer than the SharePoint path.

Why can I open a file in the browser but not from my synced folder?

The browser uses the SharePoint path, which can be up to 400 characters. The synced copy lives under a local folder such as C:\Users\name\Contoso\Site - Library, which adds characters, and Word, Excel and File Explorer stop at about 256 to 260. Shorten a folder name near the top of the path to fix it.

Does enabling Windows long paths fix OneDrive path errors?

Not for most people. File Explorer and Office desktop apps do not use the Windows long-path setting, so they still stop at about 260 characters. The OneDrive sync app itself supports longer local paths, but the files still have to be opened by apps that do not.

Which characters are not allowed in SharePoint file names?

Double quote, asterisk, colon, less than, greater than, question mark, forward slash, backslash and pipe. Names also cannot start or end with a space, end with a period, start with ~$, contain _vti_, or be a reserved name such as CON, PRN, AUX, NUL, COM1 or LPT1.

How do I find all long file paths in SharePoint?

Run a PnP PowerShell script that reads FileRef for every item and reports the longest, or run an item inventory in SharePoint Essentials Toolkit and sort by Item Url Path Length. The toolkit report is free on up to 20 sites and can be exported to Excel.

Find long SharePoint paths free on up to 20 sites

SharePoint Essentials Toolkit Community Edition is free. Inventory every file and folder with its path length and folder depth, sort, and export, on up to 20 sites per Microsoft 365 tenant. Get your free Community Edition license key.

About the author. The Cognillo SharePoint Team builds and supports SharePoint Essentials Toolkit and has worked with SharePoint administrators on permissions audits, migrations and cleanup projects since 2012.