这看起来有点微不足道,但我无法弄明白。我正在打开一个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。

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

感谢。

有帮助吗?

解决方案

查看此页底部的示例表

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

其他提示

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

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

这样的事情

string webServerRelativeUrl = site.ServerRelativeUrl +&quot; / internal / scheduletool&quot;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top