views:

86

answers:

0

Hey... I work in sharepoint 2010 and I want to sort Global Navigation's item from code(written in c#) Here is part of my function for sorting navigations items:

PublishingWeb myPublishingWeb = PublishingWeb.GetPublishingWeb(site.OpenWeb()); SPNavigationNodeCollection publishingNavigationNodes = myPublishingWeb.Navigation.GlobalNavigationNodes; SPWeb web = site.OpenWeb("/"); SPNavigationNodeCollection webNavigationNodes= web.Navigation.TopNavigationBar;

             foreach (SPNavigationNode node in webNavigationNodes)
           {

               if (node.Title == "item's name")
               {  
                   node.MoveToFirst(publishingNavigationNodes);

               }
           }

Problem is that publishingNavigationNodes don't contain items that are in navigation, and webNavigationNodes only contains items when function is called from site or webpart but when it's called from feature or Job it is empty. Does anyone know how to solve this? Thanx