2010-03-17 80 views
4

问题:在SPSite或SPWeb对象的URL中使用具有不正确大小写的SharePoint API(对象模型)创建网站列会导致新列如果试图通过“网站栏库”进行编辑,则会抛出异常。如何确定SharePoint网站的正确(区分大小写)URL

SharePoint通常非常容忍以大小写不敏感的方式接受URL,但有几种情况下它完全崩溃。例如,在创建站点列时,它以某种方式在创建时存储和使用该URL,并且在尝试通过站点列画廊(LAYOUTS中的fldedit.aspx页面)编辑字段定义时最终抛出以下错误。

Value does not fall within the expected range. 
at Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName, Boolean bThrowException) 
at Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName) 
at Microsoft.SharePoint.ApplicationPages.BasicFieldEditPage.OnLoad(EventArgs e) 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

如何可靠地获取站点/网站的正确URL? SPSite.Url和SPWeb.Url属性似乎返回它们实例化的任何情况。

换句话说,该网站集使用以下URL置备:http://server/Path/Site

然后,如果我创建使用SharePoint对象模型的新网站栏和实例的SPSite和的SPWeb对象时碰巧使用http://server/path/site,网站列将会变得可用,但是当试图通过图库访问它时,会产生上述错误。如果我更正了地址栏中的URL,我仍然可以查看/修改所讨论的SPField的定义,但生成的默认URL是伪造的。

清澈如泥?

示例代码:(这是因为案件的敏感性问题的一个坏榜样)

// note: site should be partially caps: http://server/Path/Site 
using (SPSite site = new SPSite("http://server/path/site")) { 
    using (SPWeb web = site.OpenWeb()) { 
    web.Fields.AddFieldAsXml("..."); // correct XML really here 
    } 
} 
+0

你在哪里运行创建站点列的代码?通过功能接收器? – UnhipGlint 2010-03-17 23:59:43

+0

@UnhipGlint我目前只是在服务器上的控制台应用程序中运行它。最终它可能会在特性接收器中结束,或者可能会根据需要调用服务器控件/ .ashx。 – Goyuix 2010-03-18 03:06:55

回答

1

不知道这是否是影响你,但是相对于一个已知的bug,以区分在SharePoint中的URL灵敏度。

http://blogs.msdn.com/enterprisesearch/archive/2008/01/25/crawling-case-sensitive-web-content-in-sharepoint-server-2007-and-search-server-2008.aspx

既然你是在三月发布此,你可能有安装修补程序服务包。您可能会错过注册表设置。

+0

这是很好的知道,但不幸的是似乎并没有解决网站专栏的具体情况。 – Goyuix 2010-05-13 22:13:14