MOSS 2007 - 无效的URL异常SPSite.OpenWeb(...)

时间:2008-10-10 16:21:31

标签: c# sharepoint sharepoint-2007 moss wss

这看起来有点微不足道,但我无法弄明白。我正在打开一个SPSite,然后尝试在该SPSite下打开一个SPWeb。这在VPC上工作正常,它具有相同的网站集/网站层次结构,但在生产时,我得到一个例外,告诉我当我尝试SPSite.OpenWeb(webUrl);时URL无效。我已经确认网址是正确的。

守则:

  try
        {
            SPSite scheduleSiteCol = new SPSite(branchScheduleURL);
            lblError.Text += Environment.NewLine + "Site Collection URL: " + scheduleSiteCol.Url;
            SPWeb scheduleWeb = scheduleSiteCol.OpenWeb(branchScheduleURL.Replace(scheduleSiteCol.Url, "")); //<--- Throws error on this line
            SPList scheduleList = scheduleWeb.GetList(branchScheduleURL + "/lists/" + SPContext.Current.List.Title);
            return scheduleList.GetItemById(int.Parse(testID));
        }
        catch (System.Exception ex)
        {
            lblError.Text += Environment.NewLine + ex.ToString();
            return null;
        }

注意:
branchScheduleURL实际上是包含Web URL的整个URL。

输出+异常:

  

网站集网址:https://ourSite.com/mocc   
System.ArgumentException:无效的URL:/ internal / scheduletool。在Microsoft.SharePoint.SPSite.OpenWeb(String strUrl,Boolean requireExactUrl)atMOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.GetConflictListItem(String branchScheduleURL,String testID)的Microsoft.SharePoint.SPSite.OpenWeb(String strUrl)System.NullReferenceException:对象引用未设置为对象的实例。在MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.CheckForConflicts(String [] cfcFlags1,DateTime startTime,DateTime endTime,String [] cfcFlags2)

注意:
https://ourSite.com/mocc/internal/scheduletool是我试图打开的SPWeb。

我错过了一些明显的东西吗?任何帮助将不胜感激。

感谢。

3 个答案:

答案 0 :(得分:3)

查看this page底部的示例表。

尽量不要将任何参数发送到OpenWeb()方法(第2行)。

答案 1 :(得分:1)

首先尝试获取“内部”的SPWeb对象。然后获取该对象的SubWeb SPWebCollection。从那里,尝试使用GetSubwebsForCurrentUser()方法获取“ScheduleTool”的SPWeb对象。

答案 2 :(得分:0)

它表示您的网站集URL是/ mocc,因此下面的SPWeb类似于/ mocc / internal / scheduletool。所以做一些像

这样的事情

string webServerRelativeUrl = site.ServerRelativeUrl + "/internal/scheduletool"