Beware of deleting Global Navigation nodes in SPWeb.Navigation.GlobalNodes

For a standard team site (STS#0) the GlobalNodes SPNavigationNodesCollection will contain three SPNavigationNode objects.

Home, Quick Launch and SharePoint Top Navigation Bar, these each have Ids of 1000, 1002 and 1025 respectively.

The problem occurs if you delete Quick Launch or SharePoint Top Navigation nodes. Even if you then add them back in a new ID is generated and SPWeb.Navigation.TopNavigationBar looks for child nodes under a node with an Id of 1002 (This is hard coded).

Through the API this means that SPWeb.Navigation.TopNavigationBar will always be null and through the SharePoint UI an error will be returned to the user ("Value does not exist in that range").

The only ways I have found to fix this is to delete and re-create the site or (Microsoft please close your ears) get the site id and web id and query the NavNodes table in the content database the site collection sits in and add the following records

SiteId
WebId
Eid
EidParent
NumChildren
RankChild
ElementType
Url
DocId
Name
DateLastModified
NodeMetaInfo
NonNavPage
NavSequence
ChildOfSequence
C803FD13-27FA-475F-909C-2CE5B2048E1B
A31E8093-1505-4E1C-B7CC-04D6B952A33F
1000
0
0
0
0
NULL
A31414EE-953B-44CC-A37E-4D5D643B002A
Home
2008-04-04 11:28:21.000
NULL
False
False
False
C803FD13-27FA-475F-909C-2CE5B2048E1B
A31E8093-1505-4E1C-B7CC-04D6B952A33F
1002
0
0
2
1
 
NULL
SharePoint Top Navigation
2008-04-04 11:28:21.000
NULL
False
True
False
C803FD13-27FA-475F-909C-2CE5B2048E1B
A31E8093-1505-4E1C-B7CC-04D6B952A33F
1025
0
0
1
1
 
NULL
Quick Launch
2008-04-04 11:28:21.000
NULL
True
True
False

You may also like: