2011-02-17 120 views
0

我在從其他網站集檢索列表項時遇到問題。嘗試從當前網站集中收到列表項時,我沒有問題。例如,http://myintranet.com/Departments/IT的作品。但是http://myintranet.com/sites/Departments/IT會返回錯誤。從SharePoint 2010中的其他網站集檢索列表項

if (!String.IsNullOrEmpty(SiteName) && !String.IsNullOrEmpty(SPContext.Current.Web.Url)) 
    { 
     SPSecurity.RunWithElevatedPrivileges(delegate() 
     { 
     using (SPSite intranetSite = new SPSite(SPContext.Current.Web.Url)) 
     { 
      using (SPWeb currentWeb = intranetSite.AllWebs["/sites/projects/Physics"]) 
      { 
      SPList postList = currentWeb.Lists.TryGetList("Issues");     

      if (postList != null) 
      { 
       IssueList.DataSource = postList.Items.GetDataTable(); 

       IssueList.DataBind(); 
      } 
      } 
     } 

     }); 
    } 

我沒有使用任何不同的代碼來試圖接收列表項。唯一的區別是,這次我從另一個網站集獲取列表項。

感謝您的幫助!

回答

2

問題是intranetSite.AllWebs。這隻會在您當前的網站集下獲得SPWeb對象。

您無法直接從一個網站集推斷另一個網站集。

即使/網站/項目看起來像從/的chid網站集合,它不是。 /網站只是一個管理路徑。 /和/ sites/projects與網站集層次結構處於同一級別。

你需要做的是這樣的:

if (!String.IsNullOrEmpty(SiteName) && !String.IsNullOrEmpty(SPContext.Current.Web.Url)) 
    { 
     SPSecurity.RunWithElevatedPrivileges(delegate() 
     { 

      using (SPWeb currentWeb = new SPSite("http://server/sites/projects/Physics").OpenWeb()) 
      { 
      SPList postList = currentWeb.Lists.TryGetList("Issues");     

      if (postList != null) 
      { 
       IssueList.DataSource = postList.Items.GetDataTable(); 

       IssueList.DataBind(); 
      } 
      } 

     }); 
    } 
+0

現在我終於開始明白這個管理路徑的業務。一整天都在引起我的問​​題。謝謝你的幫助。我會盡力實施這個明天。 – R100 2011-02-17 20:39:20