I am using feature stapling to add a feature to all sites in a web application. This feature creates a list, creates a site page, creates a WebPart, adds the WebPart to the site page, and then it is suppose to add the link to the page to the nav bar.
Everything is working except for the changes to the nav bar. When I manually activate the feature it works but when activated through feature stapling it does not.
Here is the code I am using for adding the WebPart to the page and modifying the navigation (or trying to). The WebPart is added to the page so I know that it is being fired.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("AboutPages/AboutPage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
AboutInformation.AboutInformation wp = new AboutInformation.AboutInformation();
wp.Title = "About";
wp.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
webParts.AddWebPart(wp, "Left", 0);
webParts.SaveChanges(wp);
web.Navigation.TopNavigationBar.AddAsLast(new Microsoft.SharePoint.Navigation.SPNavigationNode("About", @"AboutPages/AboutPage.aspx"));
web.Navigation.TopNavigationBar.AddAsLast(new Microsoft.SharePoint.Navigation.SPNavigationNode("Google", @"http://www.google.com", true));
web.Navigation.QuickLaunch.AddAsLast(new Microsoft.SharePoint.Navigation.SPNavigationNode("About", @"AboutPages/AboutPage.aspx"));
web.Navigation.QuickLaunch.AddAsLast(new Microsoft.SharePoint.Navigation.SPNavigationNode("Google", @"http://www.google.com", true));
}
EDIT: I am adding the AboutPage.aspx
in the feature that the above is called so if it is possible to add to navigation declaratively instead of programmatically that would work also. The google nav is in there just for testing purposes to see if it was an issue with AboutPage
not being fully provisioned.