设为首页 收藏本站
查看: 663|回复: 0

[经验分享] SharePoint Error : System.ArgumentException. Value does not fall within the expe

[复制链接]

尚未签到

发表于 2015-9-25 11:04:04 | 显示全部楼层 |阅读模式
之前做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:

  • Throw away the database and transfer it correctly using STSADM -o export/import or content deployment
  • Fix the incorrect links manually using the following steps

    • Open the web in SharePoint Designer
    • On the “task panes” window, pick hyperlinks.
    • For the “hyperlink” heading, click the arrow and pick (custom…)
    • In the dialog, ask to show rows where the hyperlink begins with a URLs which are not valid on the current server farm
    • 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

DSC0000.gif DSC0001.gif Code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;

namespace 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 end DSC0002.gif ");
            Console.Read ();
        }
    }
}
  运行一次搞掂,Thanks to Stefan Goßner !

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118603-1-1.html 上篇帖子: Sharepoint Two Webpart Connect 下篇帖子: Send email to multiple users with sharepoint workflow
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表