Deploy custom Navigation / SiteMap via Feature?

2019-06-06 07:14发布

问题:

You can customize the navigation in SP2010 via Site Settings > Navigation:

How would I go ahead and define a simple (!) navigation myself and deploy with via feature? I don't really want to create a custom master page - just like I would do via the frontend: Add two links to the menu and I'm happy.

I read about a custom site map provider and using a custom xml file and reference it in the web.config, but I cannot believe it is not easier to simply modify some existing links in the global navigation and add some new ones - basically create my own menu.

Let's go with an example:

Global Navigation
    Custom Folder
        Products --> lists/products
        More News --> lists/morenews
        Entertainment --> lists/entertainment
    Another Folder
        Somethingelse --> somethingelse.aspx

How would I go about and deploy this to my site and replace the global navigation?

回答1:

Turns out I'm looking for the SPWeb.Navigation Property. I can easily add links to the global navigation and the quick launch by using the AddToQuickLaunch (MSDN) method.

Microsoft even has a MSDN entry for what I was looking for: Adding Links to Quick Launch.

Once you're on track you find more information:

  • Best way to programmatically create/maintain SharePoint Quick Launch menu
  • Beware of deleting Global Navigation nodes in SPWeb.Navigation.GlobalNodes

So now I just have to add my custom navigation via a Feature Receiver and all is fine.



回答2:

In order to do this, one option would be to use asp:repeaters in the masterpage to pull in data from the global navigation. First you need to setup something in the masterpage that will pull in data from their built in navigation (site settings>navigation). Then you can style it however you want in the master page. So now if you add more entries into the navigation, they will appear the same in the navigation.

http://sharepoint2010customnavigation.blogspot.com/



回答3:

I would create an event receiver for your feature that runs the code you require. Here and here are a couple of links to get you started.