SPNavigation.GlobalNodes property

Gets the top-level navigation nodes for the current context.

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

Syntax

'Declaration
Public ReadOnly Property GlobalNodes As SPNavigationNodeCollection
    Get
'Usage
Dim instance As SPNavigation
Dim value As SPNavigationNodeCollection

value = instance.GlobalNodes
public SPNavigationNodeCollection GlobalNodes { get; }

Property value

Type: Microsoft.SharePoint.Navigation.SPNavigationNodeCollection
A collection of top-level navigation nodes.

Remarks

This property returns a collection that includes the following navigation nodes:

Examples

The following example is a console application that iterates over the collection of navigation nodes returned by the GlobalNodes property and prints the title, Id, and Url for each node.

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.OpenWeb("test"))
                {
                    string format = "{0, -30} {1, -5} {2}";
                    Console.WriteLine(format, "Title", "Id", "Url");

                    foreach (SPNavigationNode node in web.Navigation.GlobalNodes)
                    {
                        Console.WriteLine(format, node.Title, node.Id, node.Url);
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.ReadLine();
        }
    }
}
Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Navigation

Module ConsoleApp

    Sub Main()

        Using site As New SPSite("https://localhost")

            Using web As SPWeb = site.OpenWeb("test")

                Dim format As String = "{0, -30} {1, -5} {2}"
                Console.WriteLine(format, "Title", "Id", "Url")

                For Each node As SPNavigationNode In web.Navigation.GlobalNodes
                    Console.WriteLine(format, node.Title, node.Id, node.Url)
                Next

            End Using

        End Using

        Console.Write(vbCrLf & "Press ENTER to continue....")
        Console.Read()
    End Sub

End Module

See also

Reference

SPNavigation class

SPNavigation members

Microsoft.SharePoint.Navigation namespace

Microsoft.SharePoint.Navigation.SPNavigationNodeCollection

GetNodeById

GetNodeByUrl