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.
Remarks
——————————————————————————–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.”
Source:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.maxfullurllength.aspx)
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=12.0.0.0, 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!!!