del método SPNavigationNodeCollection.AddAsLast

Agrega un objeto SPNavigationNode como el último nodo de la colección.

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

Sintaxis

'Declaración
Public Function AddAsLast ( _
    node As SPNavigationNode _
) As SPNavigationNode
'Uso
Dim instance As SPNavigationNodeCollection
Dim node As SPNavigationNode
Dim returnValue As SPNavigationNode

returnValue = instance.AddAsLast(node)
public SPNavigationNode AddAsLast(
    SPNavigationNode node
)

Parámetros

Valor devuelto

Tipo: Microsoft.SharePoint.Navigation.SPNavigationNode
El nodo de navegación que se ha agregado, ahora totalmente inicializado.

Comentarios

Un objeto SPNavigationNode no se inicializa completamente hasta que se ha agregado a una colección. Si el objeto todavía no es un miembro de una colección, propiedades de solo lectura como Id y ParentId devuelven una referencia null (Nothing en Visual Basic).

Ejemplos

En el siguiente ejemplo es una aplicación de consola que agrega un vínculo a un sitio Web de secundario en la barra de vínculos superior del sitio Web primario. Tenga en cuenta que antes de agregar el vínculo, la aplicación comprueba primero para garantizar que el elemento primario no heredará vínculos. Si el elemento primario heredan vínculos, su SPNavigationNodeCollection es null y por tanto no se puede agregar un vínculo. La aplicación también comprueba si ya existe un vínculo al elemento secundario en la barra de vínculos superior del primario. Si el elemento primario no heredará vínculos y no tiene ningún vínculo existente al elemento secundario, se agrega uno.

using System;
using System.Linq;
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 child = site.OpenWeb("parent/child"))
                {
                    // Use links from parent on the child's top link bar.
                    child.Navigation.UseShared = true;

                    // If the parent web's top link bar is not inherited,
                    // add a link to the child on the parent's top link bar.
                    if (!child.ParentWeb.Navigation.UseShared)
                    {
                        // Get the parent's top link bar.
                        SPNavigationNodeCollection topnav = child.ParentWeb.Navigation.TopNavigationBar;

                        // Query for an existing link to the child.
                        SPNavigationNode node = topnav
                            .Cast<SPNavigationNode>()
                            .FirstOrDefault(n => n.Url.Equals(child.ServerRelativeUrl));

                        // No link, so add one.
                        if (node == null)
                        {
                            // Truncate a long title.
                            string linkTitle = child.Title;
                            if (linkTitle.Length > 15)
                                linkTitle = linkTitle.Substring(0, 12) + "...";

                            // Create the node.
                            node = new SPNavigationNode(linkTitle, child.ServerRelativeUrl);

                            // Add it.
                            node = topnav.AddAsLast(node);
                        }
                    }
                }
            }
            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 child As SPWeb = site.OpenWeb("parent/child")

                ' Use links from parent on the child's top link bar.
                child.Navigation.UseShared = True

                ' If the parent web's top link bar is not inherited,
                ' add a link to the child on the parent's top link bar.
                If Not child.ParentWeb.Navigation.UseShared Then

                    ' Get the parent's top link bar.
                    Dim topnav As SPNavigationNodeCollection = child.ParentWeb.Navigation.TopNavigationBar

                    ' Query for an existing link to the child.
                    Dim node As SPNavigationNode = topnav.Cast(Of SPNavigationNode)().FirstOrDefault(Function(n) n.Url.Equals(child.ServerRelativeUrl))

                    ' No link, so add one.
                    If node Is Nothing Then
                        ' Truncate a long title.
                        Dim linkTitle As String = child.Title
                        If linkTitle.Length > 15 Then
                            linkTitle = linkTitle.Substring(0, 12) + "..."
                        End If

                        ' Create the node.
                        node = New SPNavigationNode(linkTitle, child.ServerRelativeUrl)

                        ' Add it.
                        node = topnav.AddAsLast(node)
                    End If

                End If

            End Using

        End Using

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

End Module

Vea también

Referencia

clase SPNavigationNodeCollection

Miembros SPNavigationNodeCollection

Espacio de nombres Microsoft.SharePoint.Navigation

Microsoft.SharePoint.Navigation.SPNavigationNode

SPNavigationNode.Update

UseShared

MoveToLast(SPNavigationNodeCollection)