As with almost anything in SharePoint 2007, it is possible to set the navigation options for a publishing site in code. To be able to do this, you need to reference the Microsoft.SharePoint.Publishing assembly and add these using directives.
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Navigation;
Initialize
The following examples all use this initialization snippet:
SPSite site = new SPSite("http://office2007:300"); SPWeb web = site.AllWebs["intro/webcms"];
string pagename = "IntroductieCMS.aspx";
PublishingWeb pw = Microsoft.SharePoint.Publishing.PublishingWeb.GetPublishingWeb(web);
PublishingPageCollection webpages = pw.GetPublishingPages();
Example 1 – Switch “Show Pages” on
This example switches the “Show Pages” option for a publishing site on. This setting is found in SharePoint on the Modify Navigation page.

if (!pw.IncludePagesInNavigation)
{ pw.IncludePagesInNavigation = true;
pw.Update();
}
Example 2 – Exclude a page from the navigation
This sample excludes the page called “IntroductieCMS.aspx” from the navigation. This is a normal page in the Pages document library.

PublishingPage page = webpages[string.Format("Pages/{0}", pagename)]; if ((page != null) && (page.IncludeInCurrentNavigation))
{ page.CheckOut();
page.IncludeInCurrentNavigation = false;
page.Update();
page.CheckIn("changed the navigation options"); }
In this sample the page is in a Pages library that has versioning with the Require Check Out switched on. There we need to to a checkout of the item, before we can change it.
Example 3 – Add a link to the navigation
This example adds a custom link to the current navigation. This is the navigation on the left side of the page.

SPNavigationNodeCollection navNodes = pw.CurrentNavigationNodes;
SPNavigationNode newNavNode = new SPNavigationNode("e-office", "http://www.e-office.com", true); navNodes.AddAsLast(newNavNode);
newNavNode.Properties.Add("NodeType", NodeTypes.AuthoredLinkPlain.ToString()); newNavNode.Update();
By using the NodeType property, you can choose the type of link. You can also use this to add a heading to the navigation. Please make sure that you first add the node to the collection and the set the properties in the HashTable. Otherwise the Properties value will be null and your code will fail.
To add a link to the navigation on top of the page, use the GlobalNavigationNodes property of the PublishingWeb.
These are just a few very basic examples, but they should be enough to get you started.