2009-06-24 20 views
2

私はMOSS公開サイト用のサイトマップを作成しようとしていますが、2つの方法がありますが、どちらにも固執しているようです。 (例えばリスト、surverys)Sharepoint/MOSSサイトマップを作成する

私の最初のアプローチは、すでに作成され、きれいにキャッシュされているPortalSiteMapProvider、...

PublishingWeb rootWeb = PublishingWeb.GetPublishingWeb(SPContext.Current.Site.RootWeb); 

//Get the URL of the default page in the web 
string defaultPageUrl = rootWeb.DefaultPage.ServerRelativeUrl; 

PortalListItemSiteMapNode webNode = (PortalListItemSiteMapNode)PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode.FindSiteMapNode(defaultPageUrl); 

HttpContext.Current.Response.Output.WriteLine("Top Level: " + webNode.Title.ToString() + "<br />"); 

//iterate through each one of the pages and subsites 
foreach (SiteMapNode smnTopLevelItem in webNode.ParentNode.ChildNodes) 
{ 

    HttpContext.Current.Response.Output.WriteLine(smnTopLevelItem.Title.ToString() + "<br />"); 

    //if the current sitemap has children, create a submenu for it 
    if (smnTopLevelItem.HasChildNodes) 
    { 
     foreach (SiteMapNode smnChildItem in smnTopLevelItem.ChildNodes) 
     { 
     HttpContext.Current.Response.Output.WriteLine(smnChildItem.Title.ToString() + "<br />"); 
     } 
    } 
} 

HttpContext.Current.Response.End(); 

を使用することですが、これは、サイトコレクションのすべてを返すようです。私はSharepoint websを見せたいだけです。

私の他のアプローチは..コードのこの部分を使用するために離れてフラットリスト内のすべてのウェブを返すの問題から、完璧で

SPSite siteCollection = new SPSite("http://example.org"); 
SPWebCollection sites = siteCollection.AllWebs; 
foreach (SPWeb site in sites) 
{ 
    Console.WriteLine(site.Title.ToString() + " " + site.ServerRelativeUrl.ToString()); 
} 

ました。

理想的には、子Webを表示するためにインデントを追加できます。

答えて

1

おかげで、これは私が

 public ListSiteMap() 
    { 
     PortalSiteMapProvider portalProvider1 = PortalSiteMapProvider.WebSiteMapProvider; 
     portalProvider1.DynamicChildLimit = 0; 
     portalProvider1.EncodeOutput = true; 

     SPWeb web = SPContext.Current.Site.RootWeb; 

     PortalSiteMapNode webNode = (PortalSiteMapNode)portalProvider1.FindSiteMapNode(web.ServerRelativeUrl); 

     if (webNode == null || webNode.Type != NodeTypes.Area) return; 

     Console.WriteLine(webNode.Title.ToString() + " - " + webNode.Description.ToString()); 

     // get the child nodes (sub sites) 
     ProcessSubWeb(webNode); 
    } 

    private void ProcessSubWeb(PortalSiteMapNode webNode) 
    { 
     foreach (PortalSiteMapNode childNode in webNode.ChildNodes) 
     { 
      Console.WriteLine(childNode.Title.ToString() + " - " + childNode.Description.ToString()); 

      //if the current web has children, call method again 
      if (childNode.HasChildNodes) 
      { 
       ProcessSubWeb(childNode); 
      } 
     } 
    } 

思い付いたものです私はこれらの記事はあなた

http://blogs.msdn.com/ecm/archive/2007/05/23/increased-performance-for-moss-apps-using-the-portalsitemapprovider.aspx

http://blogs.mosshosting.com/archive/tags/SharePoint%20Object%20Model/default.aspx

http://www.hezser.de/blog/archive/tags/SPQuery/default.aspx

6

一般に、再帰にオブジェクトモデルを使用することは悪い考えです。これを行うには非常に時間がかかり、リソースを大量に消費します。 PortalSiteMapProviderはあらかじめキャッシュされており、ミリ秒単位でサイト構造全体を裂くことができます。

SPSite.AllWebsについては、そのプロパティはすべてのWebのフラットなリストを返します。それがそれのためのものです。 のすぐ隣にある子Webのリストが必要な場合は、SPSite.RootWeb.Websプロパティを使用してください。 .Websプロパティ内の各SPWebに再帰的にアクセスし、その.Websプロパティを順番に呼び出してツリービューを取得します。

また、オブジェクトモデルを扱う場合は、必ずすべてのウェブサイトとサイトを廃棄してください。そうしないと叙事詩の悪い問題が発生します。これには、ウェブに触れていない場合でも、すべてのウェブを.Websコレクションに廃棄することが含まれます。

編集:

falseにそのIncludePagesプロパティを設定し、唯一のウェブを返すようにPortalSiteMapProviderを取得します。

+0

OK涼しい、私はPortalSiteMapProviderを使用したいが、私は唯一のウエブに出力を制限する方法がわかりませんよ。 – Rob

2

foreachループ内のすべてのノードのタイプをPortalSiteMapNode.Typeプロパティを使用して確認し、NodeTypes.Areaタイプのノードのみを表示しようとしましたか? replysの皆のための

+0

優秀な回答! – Colin

関連する問題