PublishingWeb.ExcludeFromNavigation Method

Explicitly excludes a subsite or page from navigation.

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
Public Sub ExcludeFromNavigation ( _
    useGlobal As Boolean, _
    item As Guid _
)
'Usage
Dim instance As PublishingWeb
Dim useGlobal As Boolean
Dim item As Guid

instance.ExcludeFromNavigation(useGlobal, _
    item)
public void ExcludeFromNavigation(
    bool useGlobal,
    Guid item
)

Parameters

  • useGlobal
    Type: System.Boolean
    A Boolean value that controls whether global or current navigation is affected. Set to True to exclude the subsite from Global Navigation. Set to False to exclude the subsite from current navigation.
  • item
    Type: System.Guid
    GUID representing the ID of the item to exclude.

Remarks

After calling this method, you should call the Update method to save changes.

When hiding more than one item at the same time, it is faster to use this method to hide child objects of this Web than it is to use IncludeInNavigation properties on the child items.

Examples

Set the following references before using the sample code:

  • System.dll

  • System.Data.dll

  • System.Xml.dll

  • System.Web.dll

  • System.Configuration.dll

  • Microsoft.SharePoint.dll

  • Microsoft.SharePoint.Library.dll

  • Microsoft.SharePoint.Publishing.dll

[C#]

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;

using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Navigation;

namespace Microsoft.SDK.SharePointServer.Samples
{
    class ExcludeFromNavigationSample
    {
        // Hide all subsites of a specified site 
        // from current navigation.
        public static void HideSubSitesFromCurrentNavigation(PublishingWeb publishingWeb)
        {
            // Fetch subsites of the passed-in site.
            PublishingWebCollection subSites = publishingWeb.GetPublishingWebs();

            // Exclude each subsite from current 
            // navigation (useGlobal = false).
            foreach (PublishingWeb subSite in subSites)
            {
                // Note: you can also use
                // subSite.IncludeInCurrentNavigation = false, but
                // doing so reopens and updates the parent site for
                // each subsite. When hiding multiple subsites
                // this method performs better.
                publishingWeb.ExcludeFromNavigation(false, subSite.Web.ID);
            }

            // Save changes.
            publishingWeb.Update();
        }
    }
}

See Also

Reference

PublishingWeb Class

PublishingWeb Members

Microsoft.SharePoint.Publishing Namespace

IncludeInGlobalNavigation

IncludeInCurrentNavigation

IncludeInGlobalNavigation

IncludeInCurrentNavigation

PortalSiteMapProvider

NavigationType