Este artículo proviene de un motor de traducción automática. Mueva el puntero sobre las frases del artículo para ver el texto original.
Traducción
Original
Este tema aún no ha recibido ninguna valoración - Valorar este tema

SPNavigationNodeCollection.Add método

Agrega un objeto SPNavigationNode después del nodo especificado de la colección.

Espacio de nombres:  Microsoft.SharePoint.Navigation
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)
public SPNavigationNode Add(
	SPNavigationNode node,
	SPNavigationNode previousNode
)

Parámetros

node
Tipo: Microsoft.SharePoint.Navigation.SPNavigationNode
El objeto de nodo (SPNavigationNode) para agregar a la colección.
previousNode
Tipo: Microsoft.SharePoint.Navigation.SPNavigationNode
Especifica la posición en la colección de nodos en el que se va a agregar el nuevo objeto de nodo de forma que identifica el nodo anterior a la posición donde se inserta el nuevo nodo.

Valor devuelto

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

Un objeto SPNavigationNode no completamente se inicializan hasta que se ha agregado a una colección. Si el objeto no es aún un miembro de una colección, las propiedades de solo lectura, como Id y ParentId devuelven null.

En el ejemplo siguiente se muestra cómo agregar un vínculo en una posición específica en el menú Inicio rápido. El ejemplo es parte de un proyecto más grande que usa una característica con ámbito de Web para crear una biblioteca de documentos con el nombre de notas de la reunión. La característica incluye un controlador de eventos que implementa la clase SPFeatureReceiver , y en la característica FeatureActivated método del receptor es el código para crear la biblioteca de notas de la reunión y la adición de un vínculo al mismo bajo el encabezado de las bibliotecas en el menú Inicio rápido. Si no hay un vínculo a la biblioteca de documentos compartidos, se agrega el nuevo vínculo inmediatamente después de él. Si el menú no tiene un vínculo a los documentos compartidos, el código hace el vínculo a notas de la reunión el primer elemento por debajo del encabezado de las bibliotecas .

NotaNota

El código de ejemplo, usa varios tipos sin calificación. Para que el código compilar correctamente, necesita la clase de receptor de característica importar los espacios de nombres siguientes:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    // Get the web site where the feature is activated.
    SPWeb web = properties.Feature.Parent as SPWeb;
    if (web == null)
        return;

    // Get the Meeting Notes document library.
    SPList meetingNotes = web.Lists.TryGetList("Meeting Notes");
    if (meetingNotes == null)
    {
        // Create the library if it does not exist.
        Guid listId = web.Lists.Add("Meeting Notes", "An archive for meeting notes.", SPListTemplateType.DocumentLibrary);
        meetingNotes = web.Lists.GetList(listId, false);
    }

    // Check for an existing Quick Launch node for Meeting Notes.
    SPNavigationNode meetingNotesNode = web.Navigation.GetNodeByUrl(meetingNotes.DefaultViewUrl);

    // If a Meeting Notes node exists on Quick Launch, nothing more to do.
    if (meetingNotesNode != null)
        return;

    // Still here, so create a node for Meeting Notes.
    meetingNotesNode = new SPNavigationNode(meetingNotes.Title, meetingNotes.DefaultViewUrl);

    // Get the Libraries heading.
    SPNavigationNode librariesHeading = web.Navigation.GetNodeById((int)SPQuickLaunchHeading.Documents);

    // If the Libraries heading does not exist or it exists but has no items below it,
    // then Meeting Notes will be the first item.
    if (librariesHeading == null || librariesHeading.Children.Count == 0)
    {
        web.Navigation.AddToQuickLaunch(meetingNotesNode, SPQuickLaunchHeading.Documents);
        return;
    }

    // The Libraries heading exists. Now check for an item linking to Shared Documents.
    // If a node for Shared Documents exists, Meeting Notes will go after it.
    SPList sharedDocs = web.Lists.TryGetList("Shared Documents");
    SPNavigationNode sharedDocsNode = null;
    if (sharedDocs != null)
        sharedDocsNode = librariesHeading
            .Children
            .Cast<SPNavigationNode>()
            .FirstOrDefault(n => n.Url == sharedDocs.DefaultViewUrl);

    // A node for Shared Documents does not exist. Make Meeting Notes the first item.
    if (sharedDocsNode == null)
    {
        librariesHeading.Children.AddAsFirst(meetingNotesNode);
        return;
    }

    // A node for Shared Documents exists. Place Meeting Notes after it.
    librariesHeading.Children.Add(meetingNotesNode, sharedDocsNode);

    web.Dispose();
}

¿Te ha resultado útil?
(Caracteres restantes: 1500)

Adiciones de comunidad

AGREGAR
© 2013 Microsoft. Reservados todos los derechos.