Compartir a través de


del método SPNavigation.AddToQuickLaunch

Agrega un nodo al inicio rápido, bajo el encabezado especificado. Si el encabezado especificado no existe, se crea.

Espacio de nombres:  Microsoft.SharePoint.Navigation
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
Public Function AddToQuickLaunch ( _
    node As SPNavigationNode, _
    heading As SPQuickLaunchHeading _
) As SPNavigationNode
'Uso
Dim instance As SPNavigation
Dim node As SPNavigationNode
Dim heading As SPQuickLaunchHeading
Dim returnValue As SPNavigationNode

returnValue = instance.AddToQuickLaunch(node, _
    heading)
public SPNavigationNode AddToQuickLaunch(
    SPNavigationNode node,
    SPQuickLaunchHeading heading
)

Parámetros

Valor devuelto

Tipo: Microsoft.SharePoint.Navigation.SPNavigationNode
Devuelve el objeto SPNavigationNode que se ha agregado.

Ejemplos

La aplicación de consola siguiente agrega un vínculo a la lista de "Vínculos" bajo el encabezado "Listas", en Inicio rápido.

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())
                {
                    // 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();
        }
    }
}
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()

                ' Get the Links list or create it if it does not exist.
                Dim list As SPList = web.Lists.TryGetList("Links")

                If list Is Nothing OrElse list.BaseTemplate <> SPListTemplateType.Links Then
                    ' Create the list.
                    Dim listId As Guid = web.Lists.Add("Links", "Interesting hyperlinks", SPListTemplateType.Links)
                    list = web.Lists.GetList(listId, False)
                End If

                ' Check for an existing link to the list.
                Dim listNode As SPNavigationNode = web.Navigation.GetNodeByUrl(list.DefaultViewUrl)

                ' No link, so create one.
                If listNode Is Nothing Then
                    ' Create the node.
                    listNode = New SPNavigationNode(list.Title, list.DefaultViewUrl)

                    ' Add it to Quick Launch.
                    listNode = web.Navigation.AddToQuickLaunch(listNode, SPQuickLaunchHeading.Lists)
                End If

            End Using

        End Using

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

End Module

Vea también

Referencia

clase SPNavigation

Miembros SPNavigation

Espacio de nombres Microsoft.SharePoint.Navigation