SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

  1. Created .ascx file.
  2. Added markup from v4.master page and placed it to my control.
  3. Added OnInit event handler to SiteMapDataSource.
  4. Created custom provider.
  5. Changed provider in this event handler.

So now I have following:

<SharePoint:SPNavigationManager ID="QuickLaunchNavigationManager" runat="server"
    QuickLaunchControlId="QuickLaunchMenu" ContainedControl="QuickLaunch" EnableViewState="false"
        <asp:SiteMapDataSource SiteMapProvider="SPNavigationProvider" ShowStartingNode="False" id="QuickLaunchSiteMap" StartingNodeUrl="sid:1025" runat="server" OnInit="QuickLaunchSiteMap_Init" />
        <SharePoint:UIVersionedContent ID="UIVersionedContent2" UIVersion="4" runat="server">
                      CssClass="s4-ql" />

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=, 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
            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.

enter image description here

What should I do to remove hidden items in my control?

share|improve this question
up vote 2 down vote accepted

I solved this problem. There is my code

private SiteMapNodeCollection GetNodes(SPWeb web)
    HttpContext temp = HttpContext.Current;
        HttpRequest request = new HttpRequest("", web.Url, "");
        request.Browser = new HttpBrowserCapabilities();
        HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
        HttpContext.Current.Items["HttpHandlerSPWeb"] = web;

        ProviderSettings settings = new ProviderSettings("GlobalNavSiteMapProvider", "Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
        settings.Parameters["NavigationType"] = PortalNavigationType.Current.ToString();
        settings.Parameters["EncodeOutput"] = "true";

        PortalSiteMapProvider provider = (PortalSiteMapProvider)ProvidersHelper.InstantiateProvider(settings, typeof(PortalSiteMapProvider));
        PortalSiteMapNode currentNode = (PortalSiteMapNode)provider.CurrentNode;
        if (currentNode != null)
            return currentNode.GetNavigationChildren(NodeTypes.Default, NodeTypes.Default, OrderingMethod.Manual, AutomaticSortingMethod.Title, true, -1);
        HttpContext.Current = temp;

    return null;

I changed context because my source web is in another site collection. In this case the collection contains SiteMapNode, but don't worry you can cast it to PortalSiteMapNode and use ((PortalSiteMapNode)node).IsVisible property.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.