SPNavigationNodeCollection.Add-Methode

Fügt ein SPNavigationNode -Objekt nach dem angegebenen Knoten in der Auflistung.

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

Syntax

'Declaration
Public Function Add ( _
    node As SPNavigationNode, _
    previousNode As SPNavigationNode _
) As SPNavigationNode
'Usage
Dim instance As SPNavigationNodeCollection
Dim node As SPNavigationNode
Dim previousNode As SPNavigationNode
Dim returnValue As SPNavigationNode

returnValue = instance.Add(node, previousNode)
public SPNavigationNode Add(
    SPNavigationNode node,
    SPNavigationNode previousNode
)

Parameter

  • previousNode
    Typ: Microsoft.SharePoint.Navigation.SPNavigationNode

    Gibt die Position in der Knotenauflistung, an dem das neue Node-Objekt hinzugefügt, durch das Identifizieren von des Knotens wurden die Position, an der neue Knoten eingefügt wird.

Rückgabewert

Typ: Microsoft.SharePoint.Navigation.SPNavigationNode
Der Navigationsknoten, der nun vollständig initialisiert hinzugefügt wurde.

Hinweise

Ein SPNavigationNode -Objekt ist nicht vollständig initialisiert, bis es zu einer Auflistung hinzugefügt wurde. Wenn das Objekt noch nicht um ein Mitglied einer Auflistung ist, zurückzugeben schreibgeschützte Eigenschaften wie Id und ParentIdein Nullverweis (Nothing in Visual Basic).

Beispiele

Das folgende Beispiel zeigt, wie Sie an einer bestimmten Position auf der Schnellstartleiste einen Link hinzuzufügen. Das Beispiel ist Teil einer größeren Projekt, das ein Feature mit Web-Bereich wird verwendet, um eine Dokumentbibliothek mit dem Namen Besprechungsnotizen erstellen. Das Feature umfasst einen Ereignishandler, der die SPFeatureReceiver -Klasse implementiert, und in der Funktion des Empfängers FeatureActivated -Methode Code zum Erstellen der Bibliothek Besprechungsnotizen und eine Verknüpfung hinzugefügt, unter der Überschrift Bibliotheken , die im Schnellstartmenü ist. Ist eine Verknüpfung zu der Bibliothek Freigegebene Dokumente, wird unmittelbar nach dem die neue Verknüpfung hinzugefügt. Wenn das Menü einen Link zur freigegebene Dokumente nicht vorhanden ist, werden durch der Code dem Link Besprechungsnotizen das erste Element unter der Überschrift Bibliotheken .

Hinweis

Der Beispielcode werden mehrere Typen ohne Qualifikation verwendet. Für den Code zu kompilieren muss Ihre Featureempfängerklasse importieren Sie die folgenden Namespaces hinzu:

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();
}
Public Overrides Sub FeatureActivated(ByVal properties As SPFeatureReceiverProperties)

    'Get the web site where the feature is activated.
    Dim web As SPWeb = TryCast(properties.Feature.Parent, SPWeb)
    If web Is Nothing Then
        Return
    End If

    ' Get the Meeting Notes document library.
    Dim meetingNotes As SPList = web.Lists.TryGetList("Meeting Notes")
    If meetingNotes Is Nothing Then

        ' Create the library if it does not exist.
        Dim listId As Guid = web.Lists.Add("Meeting Notes", "An archive for meeting notes.", SPListTemplateType.DocumentLibrary)
        meetingNotes = web.Lists.GetList(listId, False)

    End If

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

    ' If a Meeting Notes node exists on Quick Launch, nothing more to do.
    If meetingNotesNode IsNot Nothing Then
        Return
    End If

    ' Still here, so create a node for Meeting Notes.
    meetingNotesNode = New SPNavigationNode(meetingNotes.Title, meetingNotes.DefaultViewUrl)

    ' Get the Libraries heading.
    Dim librariesHeading As SPNavigationNode = web.Navigation.GetNodeById(CInt(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 Is Nothing OrElse librariesHeading.Children.Count = 0 Then
        web.Navigation.AddToQuickLaunch(meetingNotesNode, SPQuickLaunchHeading.Documents)
        Return
    End If

    ' 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.
    Dim sharedDocs As SPList = web.Lists.TryGetList("Shared Documents")
    Dim sharedDocsNode As SPNavigationNode = Nothing
    If sharedDocs IsNot Nothing Then
        sharedDocsNode = librariesHeading.Children.Cast(Of SPNavigationNode)().FirstOrDefault( _
            Function(n) n.Url = sharedDocs.DefaultViewUrl)
    End If

    ' A node for Shared Documents does not exist. Make Meeting Notes the first item.
    If sharedDocsNode Is Nothing Then
        librariesHeading.Children.AddAsFirst(meetingNotesNode)
        Return
    End If

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

    web.Dispose()
End Sub

Siehe auch

Referenz

SPNavigationNodeCollection Klasse

SPNavigationNodeCollection-Member

Microsoft.SharePoint.Navigation-Namespace

Microsoft.SharePoint.Navigation.SPNavigationNode

SPNavigationNode.Update

Move(SPNavigationNodeCollection, SPNavigationNode)