Locating files and pages with URLs that are too long for SharePoint

As you may already know, SharePoint has a limitation on how long a page or file path (or URL) can be.  This was an issue with SharePoint 2007 -Joel Oleson blogged about it back in June 2007:

“When storing files the structure and files (entire path including sites, folders, and file name) cannot add up to more than 260 characters or they will see an error message or form validation error with the explanation around the URL length. “ 

Official Microsoft documentation states that the same limit holds for SharePoint 2010:

“SPSite.MaxFullUrlLength Field

Represents the maximum number of characters that can be used in the absolute URL for a site collection.


The value of this constant is 260.

The MaxFullUrlLength field is static and cannot be called on an instance object. To call this field, use SPSite.MaxFullUrlLength.”



When you’re moving, upgrading, or migrating SharePoint sites, you may run into problems with URLs that are too long for SharePoint.  You may see failures or errors when executing STSADM commands such as “stsadm -o export” or “stsadm -o import”.

I wrote a PowerShell script (see below) that allows you to take an inventory of all files in your web application and flag those files where the path (or URL) is longer than 260 characters.

You can call this script from a command line as follows:

powershell   C:\Inventory.ps1  "http://sharepointURL" >   C:\output.txt


Source code

 # This script enumerates all files at the specified URL,
 # and outputs full URL for each file,
 # along with the length of the URL.

# define EnumPages function

function EnumPages
param ($URL, $objFolder)

 # enumerate files in the root folder

 foreach ($file in $objFolder.Files)

 $result = "OK"
 $output = $URL + "/" + $objFolder.URL + "/" + $file.Name

# evaluate string length
 if ($output.length -ge 260) { $result = "TOO LONG" }

# write output

 write-host $output, ";" , $output.length, ";" $result, ";"
 # enumerate subfolders

 foreach ($subfolder in $objFolder.SubFolders)

 EnumPages $URL $subfolder


 # begin script body
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

 $siteURL = $args[0]

# create a new SPSite object

$site=new-object Microsoft.SharePoint.SPSite($siteURL)

 # enumerate files in the Rootweb

 foreach ($file in $site.Rootweb.Files)

$result = "OK"

 $output = $site.Rootweb.URL + "/" + $file.Name 

 if ($output.length -ge 260) { $result = "TOO LONG" }

  write-host $output, ";", $output.length, ";" , $result


 # enumerate folders in the Rootweb

 foreach ($folder in $site.Rootweb.Folders)

 EnumPages $site.Rootweb.URL $folder


 # enumerate subsites

 foreach ($web in $site.Allwebs)

  # enumerate files in the root web

  foreach ($file in $web.Files)

$result = "OK"

$output = $web.URL + "/" + $file.Name 

 if ($output.length -ge 260) { $result = "TOO LONG" }

 write-host $output, ";", $output.length, ";" , $result


  # enumerate folders

  foreach ($folder in $web.Folders)

  EnumPages $web.URL $folder



$site.Dispose(); ##ENFORCED DISPOSAL!!!    



10 Responses to “Locating files and pages with URLs that are too long for SharePoint”

  1. 1 James Madison March 20, 2013 at 7:32 am

    I know your blog entry is more about programming than user tools, but I made a (free) little web page that will shorten many SharePoint URLs that are too long:


    It works for views, which is the problem about 2/3rds of the time. Put the view URL in there, click the button, and you get the short version to the same place.

    Click to copy to clipboard, and paste where needed.

    It doesn’t work for full file names. A file name with full path is what it is. That you just have to shorten.

    But views get lots of very needless clutter added to them, and this page just strips it away.

  2. 3 Pieter November 18, 2013 at 6:01 am

    Thanks Andre. This saved me a lot of time

  3. 4 Thomas February 17, 2016 at 4:48 am

    It’s works perfectly with SP2013 on Server2012R2 🙂
    It’s also quite fast even if you have a lot of files

    Very useful script for migration project

  4. 5 Roksolana June 4, 2016 at 12:05 pm

    Long Path Tool help me a lot when i have an issue like file deleting or renaming the file. Also good to use if file name and file extension is too long.

  5. 6 zenkifc February 24, 2017 at 1:25 pm

    Is there a Sharepoint Online version for this? Currently running Version=

    • 7 andrei338 February 25, 2017 at 7:44 pm

      I haven’t tested it with SP Online, but the script logic is fairly simple and the underlying classes and properties haven’t really changed since SP 2010. Worth a try to see if it works, I think.

      • 8 zenkifc February 27, 2017 at 11:53 am

        Hey Andrei. Thanks for the reply. Which values in the script would I have to change? I’ve already tried inputting the correct version, URL and output path but it generates an error. Is there another set of modules that I need to import into my PS session?

  6. 9 andrei338 March 1, 2017 at 8:50 pm

    can you email me a screenshot of your error to andregalitsky at yahoo dot com and I’ll take a look.. Thanks!

  7. 10 Andrew Thiel January 11, 2018 at 6:48 am

    You Can use LONG PATH TOOL for solve this problem.It is great.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

RSS Information Week Headlines

  • An error has occurred; the feed is probably down. Try again later.

RSS SharePoint Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS InfoPath Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Joel Oleson Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Bud Ratliff blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Susan Hanley’s KM Blog

  • An error has occurred; the feed is probably down. Try again later.

Blog Stats

  • 374,603 hits

%d bloggers like this: