SiteMApprovider personnalisé ne montre pas le niveau 2 ou plus profond
-
10-12-2019 - |
Question
J'ai créé un fournisseur de plans personnalisé mais je suis incapable de le faire montrer le niveau suivant.
Voici ma première tentative:
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
{
var collection = new SiteMapNodeCollection();
var pNode = node as PortalSiteMapNode;
if (node.ParentNode == null)
{
PortalSiteMapNode global = new PortalSiteMapNode(pNode.WebNode, "1", NodeTypes.Area, "http://sharepoint2013/", "1", "1");
global.ParentNode = node;
collection.Add(global);
}
else if (node.Key == "1")
{
PortalSiteMapNode global2 = new PortalSiteMapNode((node.ParentNode as PortalSiteMapNode).WebNode, "1.1", NodeTypes.Area, "http://sharepoint2013/level1", "1.1", "1.1");
global2.ParentNode = node;
collection.Add(global2);
}
return collection;
}
Voici ma deuxième tentative (récursive):
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
{
var collection = new SiteMapNodeCollection();
var pNode = node as PortalSiteMapNode;
if (node.ParentNode == null)
{
PortalSiteMapNode level1 = new PortalSiteMapNode(pNode.WebNode, "1", NodeTypes.Area, "http://sharepoint2013/", "1", "1");
level1.ParentNode = node;
collection.Add(level1);
PortalSiteMapNode level2 = new PortalSiteMapNode(level1.WebNode, "1.1", NodeTypes.Area, "http://sharepoint2013/", "1.1", "1.1");
level1.ChildNodes.Add(level2);
}
return collection;
}
Voici le contrôle de délégué XML:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Sequence="30"
Id="QuickLaunchDataSource"
ControlClass="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapDataSourceSwitch"
ControlAssembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<Property Name="ID">QuickLaunchSiteMap</Property>
<Property Name="SiteMapProvider">MyQuicklaunchProvider</Property>
<Property Name="EnableViewState">false</Property>
<Property Name="StartFromCurrentNode">false</Property>
<Property Name="ShowStartingNode">false</Property>
<Property Name="TreatStartingNodeAsCurrent">false</Property>
<Property Name="TrimNonCurrentTypes">Heading</Property>
</Control>
</Elements>
résultat est toujours ceci:
Est-ce que je manque l'évidence ici?Cela ne peut pas être si dur ...
La solution 3
D'accord, ce n'est pas possible avec le PortalSitemAlvider.Son code papier.
Autres conseils
Vous devez définir "showstartingnode= true" dans les propriétés de contrôle des délégués du fournisseur de sitemap personnalisé.Le réglage sur False, il faut ignorer le rootnode dans la hiérarchie du site.
public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode node)
{
PortalSiteMapNode portalNode = node as PortalSiteMapNode;
if (portalNode != null)
{
if (portalNode.Type == NodeTypes.Area)
{
SiteMapNodeCollection nodeColl = base.GetChildNodes(portalNode);
SPWeb currentWeb = SPContext.Current.Web;
PortalSiteMapNode level1 = new PortalSiteMapNode(pNode.WebNode, "1", NodeTypes.Area, "http://sharepoint2013/", "1", "1");
nodeColl.Add(level1);
for (int i = 0; i < 20; i++)
{
PortalSiteMapNode level2 = new PortalSiteMapNode(level1.WebNode, "1.1" + i, NodeTypes.Area, "http://sharepoint2013/", "1.1", "1.1");
level1.ChildNodes.Add(level2);
}
return nodeColl;
}
else
{
return base.GetChildNodes(portalNode);
}
else
{
return new SiteMapNodeCollection();
}
}
Dans le masterpage, vous avez besoin de quelque chose comme celui-ci:
<sharepoint:aspmenuid=”topnavigationmenu” runat=”server” datasourceid=”topSiteMap1″ enableviewstate=”false” accesskey=”">” Orientation=”Horizontal” StaticDisplayLevels=”3″ MaximumDynamicDisplayLevels=”3″ DynamicHorizontalOffset=”0″ StaticPopoutImageUrl=”/_layouts/images/menudark.gif” StaticPopoutImageTextFormatString=”" DynamicHoverStyle-BackColor=”#CBE3F0″ SkipLinkText=”" StaticSubMenuIndent=”0″ CssClass=”ms-topNavContainer”>
<staticmenustyle/><staticmenuitemstyle cssclass=”ms-topnav” itemspacing=”0px”/><staticselectedstyle cssclass=”ms-topnavselected”/><statichoverstyle cssclass=”ms-topNavHover”/><dynamicmenustyle backcolor=”#F2F3F4″ bordercolor=”#A7B4CE” borderwidth=”1px”/><dynamicmenuitemstyle cssclass=”ms-topNavFlyOuts”>/><dynamicselectedstyle cssclass=”ms-topNavFlyOutsSelected”/></SharePoint:AspMenu>
<asp:sitemapdatasource showstartingnode=”False” sitemapprovider=”MyCustomNavigationProvider” id=”topSiteMap1″ runat=”server” startfromcurrentnode=”true”>
http://msdn.microsoft.com /en-us/library/ms466994(v=Office.14).aspx
et
Ajouter ceci:
showstartingnode="FALSE" Il doit être faux sinon par défaut, c'est défini sur true
comme le code ci-dessus traverse (fabriqué sans tests;) mon mauvais) et je ne connais pas spécifiquement l'erreur et quelle ligne la cause, vous pouvez l'utiliser à la place:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Navigation;
using System.Web;
using System.Web.UI.WebControls;
using System.Configuration;
namespace MyCustomNav
{
public class Navigation: PortalSiteMapProvider
{
public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode
node)
{
PortalSiteMapNode pNode = node as PortalSiteMapNode;
if (pNode != null)
{
if (pNode.Type == NodeTypes.Area)
{
SiteMapNodeCollection nodeColl = base.GetChildNodes(pNode);
PortalSiteMapNode childNode= new PortalSiteMapNode(pNode.WebNode, "1", NodeTypes.Area, "http://sharepoint2013/", "1", "1");
PortalSiteMapNode childNode1 = new PortalSiteMapNode(level1.WebNode, "1.1" + i, NodeTypes.Area, "http://sharepoint2013/", "1.1", "1.1");
nodeColl.Add(childNode);
SiteMapNodeCollection test = new SiteMapNodeCollection();
test.Add(childNode1);
childNode.ChildNodes = test;
return nodeColl;
}
else
return base.GetChildNodes(pNode);
}
else
return new SiteMapNodeCollection();
}
}
}
ajoutez ceci au web.config
<add name="MyCustomNavigationProvider" type="MyCustomNav.Navigation, MyCustomNav"
NavigationType="Current" />
Ajoutez ceci au Masterpage sous Contentplaceholder
<SharePoint:AspMenu
ID="TopNavigationMenu"
Runat="server"
DataSourceID="topSiteMap1"
EnableViewState="false"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
Orientation="Horizontal"
StaticDisplayLevels="1"
MaximumDynamicDisplayLevels="3"
DynamicHorizontalOffset="0"
StaticPopoutImageUrl="/_layouts/images/menudark.gif"
StaticPopoutImageTextFormatString=""
DynamicHoverStyle-BackColor="#CBE3F0"
SkipLinkText=""
StaticSubMenuIndent="0"
CssClass="ms-topNavContainer">
<StaticMenuStyle/>
<StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
<StaticSelectedStyle CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
<DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE"
BorderWidth="1px"/>
<DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
<DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
<DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
</SharePoint:AspMenu>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="MyCustomNavigationProvider"
id="topSiteMap1"
runat="server"
StartFromCurrentNode="true"/>
Ammend le code pour répondre à vos besoins!
http://msdn.microsoft.com /en-us/library/cc789625(v=Office.14).aspx