2011-01-13 12 views
0

http://msdn.microsoft.com/en-us/library/ms462161.aspxの例を見て、すべてのサイトとリストを取得しました。ドロップダウンにバインドしていますが、各サイトのすべてのリストを取得するので、サイト名はドロップダウンに何度も表示されます欲しいです。すべてのリストを取得せずにサイトコレクションのすべてのサイトを取得しますか?

私のコードは次のとおりです。

private void getSites() 
{ 
    SPSite oSiteCollection = SPContext.Current.Site; 
    SPWebCollection collWebsite = oSiteCollection.AllWebs; 

    for (int i = 0; i < collWebsite.Count; i++) 
    { 
     using (SPWeb oWebsite = collWebsite[i]) 
     { 
      SPListCollection collList = oWebsite.Lists; 

      for (int j = 0; j < collList.Count; j++) 
      { 
       ddlParentSite.Items.Add(new ListItem(SPEncode.HtmlEncode(collWebsite[i].Title))); 
      } 
     } 
    } 
} 

にはどうすればいいのサイトだけではなく自分のリストを得ることができますか?

ありがとうございます。

+2

嫌なピーターですが、そのコードが何をしているのか理解しようと努力しましたか? – Ryan

答えて

0

リストを追加するコードをコメントアウトするだけです。以下を参照してください:

private void getSites() 
{ 
    SPSite oSiteCollection = SPContext.Current.Site; 
    SPWebCollection collWebsite = oSiteCollection.AllWebs; 

    for (int i = 0; i < collWebsite.Count; i++) 
    { 
     ddlParentSite.Items.Add(new ListItem(SPEncode.HtmlEncode(collWebsite[i].Title))); 
    } 
} 
+2

廃棄または使用は、AllWebs []インデクサで使用する必要があります。 http://blogs.msdn.com/b/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_130 –

+0

合意... ........ –

関連する問題