(String, String, Boolean) del constructor SPNavigationNode
Crea una nueva instancia de la clase SPNavigationNode y especifica el nombre para mostrar, las ubicaciones y si el nuevo nodo es interno o externo.
Espacio de nombres: Microsoft.SharePoint.Navigation
Ensamblado: Microsoft.SharePoint (en Microsoft.SharePoint.dll)
Sintaxis
'Declaración
Public Sub New ( _
title As String, _
url As String, _
isExternal As Boolean _
)
'Uso
Dim title As String
Dim url As String
Dim isExternal As Boolean
Dim instance As New SPNavigationNode(title, url, _
isExternal)
public SPNavigationNode(
string title,
string url,
bool isExternal
)
Parámetros
title
Tipo: System.StringNombre para mostrar para el nodo. El valor de cadena puede ser una expresión de recurso, como "$Resources: core, announceList", donde "principal" es el nombre de un archivo de recursos (.resx) y "announceList" es el nombre de un recurso.
url
Tipo: System.StringDirección URL del nodo.
isExternal
Tipo: System.Booleantrue si la dirección URL que se pasa como los segundo puntos de argumento a una ubicación externa; en caso contrario, false.
Comentarios
Si el valor del parámetro isExternal es false, el constructor intenta crear un nodo interno; Si se produce un error en el constructor, produce una excepción.
El nuevo objeto SPNavigationNode no se inicializa completamente hasta que se ha agregado a una colección. Para obtener más información, vea la clase SPNavigationNodeCollection .
Ejemplos
En el siguiente ejemplo es una aplicación de consola que crea un encabezado de inicio rápido para obtener una lista de vínculos y agrega un vínculo a una página Web externa como un elemento por debajo del encabezado.
Cuando la aplicación crea el objeto SPNavigationNode para el encabezado, llama al primer constructor de (dos-parámetro) porque el destino para el nodo es interno, una lista en el sitio Web actual. Cuando crea el vínculo por debajo del encabezado, la aplicación llama al segundo constructor (tres parámetros) porque el destino para el nuevo nodo es una página en un sitio Web externo.
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 web = site.OpenWeb("test"))
{
// 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)
{
Console.WriteLine("Creating links list.");
// Create the list.
Guid listId = web.Lists.Add("Links",
"A list of interesting Web pages.",
SPListTemplateType.Links);
list = web.Lists.GetList(listId, false);
}
// Create a link field value.
SPFieldUrlValue msdnValue = new SPFieldUrlValue();
msdnValue.Description = "SharePoint Developer Center";
msdnValue.Url = " https://msdn.microsoft.com/sharepoint";
// Check if the list already has this link.
SPListItem msdnItem = null;
foreach (SPListItem item in list.Items)
{
Object rawValue = item[SPBuiltInFieldId.URL];
SPFieldUrlValue typedValue = new SPFieldUrlValue(rawValue.ToString());
if (typedValue.Url == msdnValue.Url)
{
msdnItem = item;
continue;
}
}
// If it does not...
if (msdnItem == null)
{
Console.WriteLine("Adding a new link to the list.");
// Create a new list item and set the URL field value.
msdnItem = list.Items.Add();
msdnItem[SPBuiltInFieldId.URL] = msdnValue;
msdnItem.Update();
}
// Get the QuickLaunch heading node for the links list.
SPNavigationNode linksNode = web
.Navigation
.QuickLaunch
.Cast<SPNavigationNode>()
.FirstOrDefault(n => n.Title == list.Title);
// Create the heading if it does not exist.
if (linksNode == null)
{
Console.WriteLine("Creating a Quick Launch heading.");
// Create the node.
linksNode = new SPNavigationNode(list.Title, list.DefaultViewUrl);
// Add the node as a new QuickLaunch heading.
linksNode = web.Navigation.QuickLaunch.AddAsLast(linksNode);
}
Console.WriteLine("Adding a navigation node below the Quick Launch heading.");
// Create an external navigation node.
SPNavigationNode msdnNode = new SPNavigationNode(msdnValue.Description, msdnValue.Url, true);
// Add the MSDN node to QuickLaunch below the Links heading.
msdnNode = linksNode.Children.AddAsFirst(msdnNode);
}
}
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("test")
' 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
Console.WriteLine("Creating links list.")
' Create the list.
Dim listId As Guid = web.Lists.Add("Links", _
"A list of interesting Web pages.", _
SPListTemplateType.Links)
list = web.Lists.GetList(listId, False)
End If
' Create a link field value.
Dim msdnValue As New SPFieldUrlValue()
msdnValue.Description = "SharePoint Developer Center"
msdnValue.Url = "https://msdn.microsoft.com/sharepoint"
' Check if the list already has this link.
Dim msdnItem As SPListItem = Nothing
For Each item As SPListItem In list.Items
Dim rawValue As Object = item(SPBuiltInFieldId.URL)
Dim typedValue As New SPFieldUrlValue(rawValue.ToString())
If typedValue.Url = msdnValue.Url Then
msdnItem = item
Continue For
End If
Next
' If it does not...
If msdnItem Is Nothing Then
Console.WriteLine("Adding a new link to the list.")
' Create a new list item and set the URL field value.
msdnItem = list.Items.Add()
msdnItem(SPBuiltInFieldId.URL) = msdnValue
msdnItem.Update()
End If
' Get the QuickLaunch heading node for the links list.
Dim linksNode As SPNavigationNode = web.Navigation.QuickLaunch.Cast(Of SPNavigationNode)().FirstOrDefault( _
Function(n) n.Title = list.Title)
' Create the heading if it does not exist.
If linksNode Is Nothing Then
Console.WriteLine("Creating a Quick Launch heading.")
' Create the node.
linksNode = New SPNavigationNode(list.Title, list.DefaultViewUrl)
' Add the node as a new QuickLaunch heading.
linksNode = web.Navigation.QuickLaunch.AddAsLast(linksNode)
End If
Console.WriteLine("Adding a navigation node below the Quick Launch heading.")
' Create an external navigation node.
Dim msdnNode As New SPNavigationNode(msdnValue.Description, msdnValue.Url, True)
' Add the MSDN node to QuickLaunch below the Links heading.
msdnNode = linksNode.Children.AddAsFirst(msdnNode)
End Using
End Using
Console.Write(vbCrLf & "Press ENTER to continue....")
Console.Read()
End Sub
End Module