Export (0) Print
Expand All

SPNavigation.AddToQuickLaunch method

Adds a node to the Quick Launch under the specified heading. If the specified heading does not exist, it is created.

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

public SPNavigationNode AddToQuickLaunch(
	SPNavigationNode node,
	SPQuickLaunchHeading heading
)

Parameters

node
Type: Microsoft.SharePoint.Navigation.SPNavigationNode

The node to be added.

heading
Type: Microsoft.SharePoint.Navigation.SPQuickLaunchHeading

The heading under which the node is to be added.

Return value

Type: Microsoft.SharePoint.Navigation.SPNavigationNode
Returns the SPNavigationNode object that was added.

The following console application adds a link to the "Links" list under the "Lists" heading in Quick Launch.

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    // Get the Links list or create it if it does not exist.
                    SPList list = web.Lists.TryGetList("Links");

                    if (list == null || list.BaseTemplate != SPListTemplateType.Links)
                    {
                        // Create the list.
                        Guid listId = web.Lists.Add("Links", "Interesting hyperlinks", SPListTemplateType.Links);
                        list = web.Lists.GetList(listId, false);
                    }

                    // Check for an existing link to the list.
                    SPNavigationNode listNode = web.Navigation.GetNodeByUrl(list.DefaultViewUrl);
 
                    // No link, so create one.
                    if (listNode == null)
                    {
                        // Create the node.
                        listNode = new SPNavigationNode(list.Title, list.DefaultViewUrl);

                        // Add it to Quick Launch.
                        listNode = web.Navigation.AddToQuickLaunch(listNode, SPQuickLaunchHeading.Lists);
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.ReadLine();
        }
    }
}
Show:
© 2014 Microsoft