I have to create web control that can be placed to master page. This control should display Quick Launch navigation from web that is defined in control properties. Also this page should contain own Quick Launch navigation menu. I did this steps:
- Created .ascx file.
- Added markup from v4.master page and placed it to my control.
- Added OnInit event handler to SiteMapDataSource.
- Created custom provider.
- Changed provider in this event handler.
So now I have following:
<SharePoint:SPNavigationManager ID="QuickLaunchNavigationManager" runat="server"
QuickLaunchControlId="QuickLaunchMenu" ContainedControl="QuickLaunch" EnableViewState="false"
CssClass="ms-quicklaunch-navmgr">
<div>
<asp:SiteMapDataSource SiteMapProvider="SPNavigationProvider" ShowStartingNode="False" id="QuickLaunchSiteMap" StartingNodeUrl="sid:1025" runat="server" OnInit="QuickLaunchSiteMap_Init" />
<SharePoint:UIVersionedContent ID="UIVersionedContent2" UIVersion="4" runat="server">
<contenttemplate>
<SharePoint:AspMenu
DataSourceId="QuickLaunchSiteMap"
ID="V4QuickLaunchMenu"
runat="server"
EnableViewState="false"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Vertical"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="0"
SkipLinkText=""
CssClass="s4-ql" />
</contenttemplate>
</SharePoint:UIVersionedContent>
</div>
</SharePoint:SPNavigationManager>
In practice this section has to UIVersionedContent, I removed first to reduce code in my question.
In control codebehinde I have:
public void QuickLaunchSiteMap_Init(object sender, EventArgs e)
{
using (SPSite site = new SPSite(WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
ProviderSettings provederSettings = new ProviderSettings("QuickLanchProvider", "namespase.QuickLanchProvider, assemblyname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=token");
QuickLanchProvider provider = (QuickLanchProvider)ProvidersHelper.InstantiateProvider(provederSettings, typeof(QuickLanchProvider));
provider.WebUrl = web.Url;
QuickLaunchSiteMap.Provider = provider;
}
}
}
Also I created Custom provider to override Web property of SPNavigationProvider.
public class QuickLanchProvider : SPNavigationProvider
{
public string WebUrl { get; set; }
protected override SPWeb Web
{
get
{
SPSite site = new SPSite(WebUrl);
SPWeb web = site.OpenWeb();
return web;
}
}
}
Now I can use this control, but... this control displays all nodes from a web navigation. But there several nodes that are hidded from user.
What should I do to remove hidden items in my control?