문제

나는 Moss Publishing 사이트를위한 사이트 맵을 만들려고 노력하고 있습니다. 두 가지 접근 방식이 있지만 두 가지 접근 방식이 모두 붙어있는 것 같습니다.

나의 첫 번째 접근법은 이미 만들어지고 멋지게 캐시 된 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();

그러나 이것은 사이트 컬렉션의 모든 것을 반환하는 것으로 보입니다 (예 : 목록, Surverys). SharePoint 웹 만 보여주고 싶습니다.

나의 다른 접근법은이 코드를 사용하는 것이 었습니다 ..

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

모든 웹을 평평한 목록에 반환하는 문제와는 별도로 완벽합니다.

이상적으로는 어린이 웹을 보여주기 위해 들여 쓰기를 추가 할 수 있기를 원합니다.

도움이 되었습니까?

해결책 3

답장을 보내 주셔서 감사합니다. 이것이 제가 생각해 낸 것입니다.

        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/incressed-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

다른 팁

일반적으로 재귀를 위해 객체 모델을 사용하는 것은 나쁜 생각입니다. 이를 수행하는 것은 매우 느리고 리소스 집약적입니다. PortalSiteMapProvider 당신을 위해 미리 준비되어 있으며 전체 사이트 구조를 밀리 초로 찢을 수 있습니다.

당신의 질문에 대해 SPSite.AllWebs, 그 속성은 모든 웹의 평평한 목록을 반환합니다. 그게 바로 그게되었습니다. 만 목록을 원한다면 즉각적인 어린이 웹, 사용하십시오 SPSite.RootWeb.Webs 재산. 각각을 되찾아주세요 SPWeb 에서 .Webs 재산을 부르십시오 .Webs 트리 뷰를 얻을 수있는 속성.

또한 객체 모델을 처리 할 때 모든 웹과 사이트를 처리하십시오. 그렇지 않으면 서사시 나쁜 문제가 발생합니다. 여기에는 모든 웹을 처리하는 것이 포함됩니다 .Webs 만지지 않았더라도 컬렉션.

편집하다:

PortalsItemApprovider가 웹 만 반환하도록하려면 SET을 설정하십시오. IncludePages 속성 false.

TormalSitemapNode.type 속성을 사용하여 Foreach 루프의 모든 노드 유형을 확인하고 유형 Nodetypes.area의 노드 만 표시해 보셨습니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top