Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to add a page to my site definition which is hidden ie. doesn't appear in the navigation, by default.

The page is provisioned in the onet.xml file as follows;

<File Url="SomePage.aspx" Type="GhostableInLibrary" Path="default.aspx">
    <Property Name="Hidden" Value="TRUE" />
    <Property Name="Title" Value="Some Page" />
    <Property Name="ContentType" Value="$Resources:cmscore,contenttype_welcomepage_name;" />
    <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/pagelayouts/mypagelayout.aspx, My Page Layout" />            
</File>

As you can see I have tried setting a property of Hidden but this seems to have no effect. Is there any way to set the page to be created in the site but not shown int he navigation. I have relatively limited experience with site definitions so am probably approaching it wrong?

UPDATE: I decided to approach this a different way and "simply" hide the navigation item in a feature event receiver run when the site is provisioned. However this turns out to be far from simple.

At first I tried to access the Navigation of the SPWeb

((SPWeb)properties.Feature.Parent).Navigation.TopNavigationBar;

But this is a null reference. So I created a PublishingWeb from the web and looked in there

PublishingWeb pw = PublishingWeb.GetPublishingWeb((SPWeb)properties.Feature.Parent);
pw.Navigation.GlobalNavigationNodes;

But this is also a null reference. Some searching on Google turned up this article - http://blog.mastykarz.nl/programmatically-configuring-menu-items-sharepoint-2010/ - which explains that the navigation is not populated until it is first updated through the UI and provides a fairly low level powershell solution to populate this navigation by creating a fake SPContext, grabbing a PortalSiteMapProvider and getting the navigation from there. I rewrote this into my feature receiver and have code looking like this:

        SPWeb web = (SPWeb) properties.Feature.Parent;
        PublishingWeb pw = PublishingWeb.GetPublishingWeb((SPWeb)properties.Feature.Parent);

        HttpRequest request =  new HttpRequest("", web.Url, "");
        StringWriter sw = new StringWriter();
        HttpResponse response = new HttpResponse(sw);
        HttpContext.Current = new HttpContext(request, response);
        SPControl.SetContextWeb(HttpContext.Current, web);

        ProviderSettings ps = new ProviderSettings("CombinedNavSiteMapProvider", "Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
        ps.Parameters["NavigationType"] = "Combined";
        ps.Parameters["EncodeOutput"] = "true";
        PortalSiteMapProvider psmp = (PortalSiteMapProvider) ProvidersHelper.InstantiateProvider(ps, typeof(Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider));
        PortalSiteMapNode current = (PortalSiteMapNode) psmp.CurrentNode;
        SiteMapNodeCollection nodes = current.GetNavigationChildren(NodeTypes.Default, NodeTypes.Default, OrderingMethod.Manual, AutomaticSortingMethod.Title, true, -1);

Alas the nodes collection is empty. I have tried using the GlobalNavSiteMapProvider and the CombinedNavSiteMapProvider with the same results. However when the receiver finishes the site does indeed have navigation items.

This seems like such a basic requirement that nearly every SharePoint development would need; some deployable control of navigation.

Is this really the way we are supposed to do this? Is there not a simple solution? And if it is the recommended way does anybody know why the nodes collections are always empty for me?

share|improve this question
    
What is the purpose of your page? Does it have to be in a page library? Can the page be customized by some privileged users? –  Steve B Jul 2 '12 at 13:50
    
It is in effect, although a simplification, a 'results' page, however the results are displayed by a web part and there is other content on the page which can be customized by content editors, administrators etc. The page should only be reached by 'searching' as without context it is useless, but is a publishing page with workflow for content updates too. –  robwilliams Jul 3 '12 at 8:45
add comment

2 Answers

Provision the file not to a doc library but to a folder (or even to the root folder of the site, where default.aspx lives). It will be all but invisible from the web interface(unless you create a nav link), however it will be visible to site admins via SharePoint Designer(if they know where to look).

share|improve this answer
    
The site, or at least the web containing the page in question, is public internet and the page should be accessible to anonymous users. However we naturally want anonymous access restricted to a limited number of lists/libraries. If I put the page in a folder, won't this mean that I can't make it accessible to anonymous users? What I really want is a solution to adding it to a library, but without adding it to the navigation. –  robwilliams Jul 3 '12 at 9:09
add comment
up vote 0 down vote accepted

After revisiting this problem several times and wasting much time on trying to find a resolution I have resorted to a small piece of custom Javascript which updates the menu on page load to hide and add items as required.

share|improve this answer
add comment

Your Answer

 
discard

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.