2008-10-10 51 views
0

這看起來有些微不足道,但我一直無法弄清楚。我打開一個SPSite,然後嘗試打開該SPSite下的SPWeb。這在VPC上運行良好,它具有相同的Site Collection/Site層次結構,但在生產中,當我嘗試SPSite.OpenWeb(webUrl)時,我得到一個異常告訴我URL無效。我已驗證該網址是否正確。MOSS 2007 - 無效的URL異常SPSite.OpenWeb(...)

驗證碼:

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實際上是整個URL,包括網頁的URL爲好。

輸出+例外:

網站集URL:https://ourSite.com/mocc
System.ArgumentException:無效的URL:/內部/ scheduletool。 Microsoft.SharePoint.SPSite.OpenWeb(String strUrl,Boolean requireExactUrl)at Microsoft.SharePoint.SPSite.OpenWeb(String strUrl)at MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.GetConflictListItem(String branchScheduleURL,String testID)System.NullReferenceException:未將對象引用設置爲對象的實例。在MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.CheckForConflicts(字符串[] cfcFlags1,日期時間開始時間,日期時間結束時間,字符串[] cfcFlags2)

注:
https://ourSite.com/mocc/internal/scheduletool是我試圖打開的SPWeb。

我錯過了一些明顯的東西嗎?任何幫助將不勝感激。

謝謝。

回答

3

查看this page底部的示例表。

嘗試不向OpenWeb()方法(第2行)發送任何參數。

+0

謝謝!我沒有意識到SPSite的構造函數記住了原來的URL通過。我認爲它只是將網址剝離到網站集,而忽略了其餘的網址。 – AdamBT 2008-10-14 14:46:02

1

嘗試首先爲「內部」獲取SPWeb對象。然後獲取該SubWeb SPWebCollection和對象。從此,嘗試使用GetSubwebsForCurrentUser()方法獲取「ScheduleTool」的SPWeb對象。

0

它說你的網站集URL是/ mocc,因此你的SPWeb下面會是/ mocc/internal/scheduletool。所以做一些像

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