之前做SharePoint的时候遇到这个错误 .....
System.ArgumentException. Value does not fall within the expected range.    
at Microsoft.SharePoint.Library.SPRequestInternalClass.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder)     
at Microsoft.SharePoint.Library.SPRequest.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder)     
at Microsoft.SharePoint.SPWeb.GetMetadataForUrl(String relUrl, Int32 mondoProcHint, Guid& listId, Int32& itemId, Int32& typeOfObject, Object& fileOrFolder)     
at Microsoft.SharePoint.SPWeb.GetFileOrFolderObject(String strUrl)     
at Microsoft.SharePoint.Publishing.CommonUtilities.GetFileFromUrl(String url, SPWeb web)
最后在blogs.technet.com找到了解决办法
原因就是:
The reason for this problem is that backup/restore does not adjust the references from the publishing page objects in the Pages library to their Page Layouts. These URLs are sometimes stored as absolute URLs including the server name. And this server name is the server name of the old server farm which cannot be resolved on the new farm.

解决办法 :
In case that you have run into the above problem you have two options:
  1. Throw away the database and transfer it correctly using STSADM -o export/import or content deployment
  2. Fix the incorrect links manually using the following steps
    1. Open the web in SharePoint Designer
    2. On the “task panes” window, pick hyperlinks.
    3. For the “hyperlink” heading, click the arrow and pick (custom…)
    4. In the dialog, ask to show rows where the hyperlink begins with a URLs which are not valid on the current server farm
    5. For each of the files, right click and say “Edit hyperlink…” and Replace hyperlink with the hyper link that is valid on the current server farm

他那里有个stsadm扩展可以解决问题, 不过在客户那里我只有写个Console给客户自己运行了
新建一个Console Application

 SharePoint.Panda.FixPageLayout {
    class Program {
        
static void Main ( string [] args ) {
            
const string MASTER_PAGE_LIB = "_catalogs/masterpage";

            Console.WriteLine ( 
"Please input site url and click enter : " );
            
string SiteCollectionUrl = Console.ReadLine ();

            
if ( !Uri.IsWellFormedUriString ( SiteCollectionUrl, UriKind.Absolute ) ) {
                Console.WriteLine ( 
"Site url not allow be null " );
                
return;
            }

            
try {
                SPSecurity.RunWithElevatedPrivileges ( 
delegate {
                    
// get the site collection
                    using ( SPSite site = new SPSite ( SiteCollectionUrl ) ) {

                        
// get the servername from RootWeb as it should be
                        using ( SPWeb RootWeb = site.RootWeb ) {
                            SiteCollectionUrl 
= RootWeb.Url.ToLower ();
                            
if ( !SiteCollectionUrl.EndsWith ( "/" ) )
                                SiteCollectionUrl 
+= "/";
                        }

                        
// check each site in the site collection
                        foreach ( SPWeb web in site.AllWebs ) {
                            
try {
                                
// check if the site is a publishing site
                                if ( PublishingWeb.IsPublishingWeb ( web ) ) {
                                    PublishingWeb pubWeb 
= PublishingWeb.GetPublishingWeb ( web );

                                    
// check each Publishing page in the current publishing site
                                    foreach ( PublishingPage page in pubWeb.GetPublishingPages () ) {
                                        
// retrieve the page layout of the publishing page
                                        string pageLayout = page.ListItem.Properties ["PublishingPageLayout"as string;

                                        
// check for correct syntax of the page layout URL
                                        if ( pageLayout != null )
                                            pageLayout 
= pageLayout.ToLower ();

                                        
if ( String.IsNullOrEmpty ( pageLayout ) ) {
                                            Console.WriteLine ( 
" Page \"{0}\" does not have a Page Layout assigned.\n", page.Uri );
                                        } 
else if ( !pageLayout.Contains ( MASTER_PAGE_LIB ) ) {
                                            Console.WriteLine ( 
" The Page Layout {0} for Page \"{1}\" does not point to the masterpage document library.\n",
                                                pageLayout, page.Uri );
                                        } 
else if ( !pageLayout.StartsWith ( SiteCollectionUrl ) && pageLayout.StartsWith ( "http" ) ) {
                                            
// here we have a page which has a page layout with different URL which we have to fix
                                            Console.WriteLine ( " Page {0} has incorrect PageLayout Url", page.Uri );
                                            Console.WriteLine ( 
" Old URL: {0}", pageLayout );
                                            
string pageLayoutWithoutPrefix = pageLayout.Substring ( pageLayout.IndexOf ( MASTER_PAGE_LIB ) );
                                            
string newPageLayout = SiteCollectionUrl + pageLayoutWithoutPrefix;

                                            
// perform the update in a try/catch block to cover problems
                                            try {
                                                
int version = page.ListItem.File.MinorVersion;
                                                page.CheckOut ();
                                                page.ListItem.Properties [
"PublishingPageLayout"= newPageLayout;
                                                page.ListItem.File.Properties [
"PublishingPageLayout"= newPageLayout;
                                                page.ListItem.Update ();
                                                page.CheckIn ( 
"PublishingPageLayout corrected" );

                                                
//major version means that the item was published. Lets publish it again.
                                                if ( version == 0 )
                                                    page.ListItem.File.Publish ( 
"PublishingPageLayout corrected" );

                                                Console.WriteLine ( 
"Fixed URL: {0}\n", newPageLayout );
                                            } 
catch ( Exception e ) {
                                                Console.WriteLine ( 
"An error occurred while trying to fix the URL to the page layout:\n{0}", e );
                                            }
                                        }
                                    }
                                }
//if Publishing web

                            } 
finally {
                                
// don't forget to dispose the SPWeb object
                                web.Dispose ();
                            }
                        }
                        Console.WriteLine ( 
"Fix page layout have been finish " );
                    }
//using SPSite
                } );
            } 
catch ( System.IO.FileNotFoundException ex ) {
                Console.WriteLine ( 
"{0}", ex.Message );
            } 
catch ( Exception ex ) {
                Console.WriteLine ( 
"An error has occured: {0}", ex.Message );
            }         
            Console.WriteLine(
"press any key to endSharePoint Error : System.ArgumentException. Value does not fall within the expected range");
            Console.Read ();
        }
    }
}

运行一次搞掂,Thanks to Stefan Goßner !

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-05-18
  • 2021-10-27
  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2021-06-27
  • 2022-02-23
  • 2021-11-07
  • 2021-11-10
  • 2021-10-22
  • 2021-12-03
相关资源
相似解决方案