Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

PortalNavigation class

Represents navigation for portal pages and other portal navigation objects.

System.Object
  Microsoft.SharePoint.Publishing.Navigation.PortalNavigation

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

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class PortalNavigation

The following code example configures portal navigation for a specified site.

/ Assemblies that need to be referenced in this sample:
//     Microsoft.SharePoint.dll
//     Microsoft.SharePoint.Publishing.dll

using System;

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

namespace Microsoft.SDK.SharePointServer.Samples
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Configure the portal navigation settings for a particular site.
            using (SPSite siteCollection = new SPSite("http://yourServer"))
            {
                using (SPWeb site = siteCollection.OpenWeb("/site1"))
                {
                    PublishingWeb pubSite = PublishingWeb.GetPublishingWeb(site);
                    PortalNavigation portalNav = pubSite.Navigation;

                    // Show pages in the current navigation (on the left for LTR languages using SharePoint's
                    // default Master Pages).
                    portalNav.CurrentIncludePages = true;

                    // Increase the number of dynamic children in the current navigation to 50.
                    portalNav.CurrentDynamicChildLimit = 50;

                    // Disable global navigation inheritance, establishing the site as the new global navigation root
                    // for any sites below it; also disable the sibling display behavior for the current navigation.
                    portalNav.InheritGlobal = false;
                    portalNav.ShowSiblings = false;

                    // Enable automatic sorting for all of the site's navigation items.
                    portalNav.OrderingMethod = OrderingMethod.Automatic;

                    using (SPWeb siteToHide = siteCollection.OpenWeb("/site1/site2"))
                    {
                        // Hide a specific sub-site from display in global navigation.
                        portalNav.ExcludeFromNavigation(true, siteToHide.ID);

                        // Hide a specific sub-site from display in current navigation.
                        portalNav.ExcludeFromNavigation(false, siteToHide.ID);
                    }

                    // Save the changes to the store.
                    pubSite.Update();
                }
            }
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft