R – Customize Current Navigation Via SharePoint API

apinavigationsharepointsharepoint-2007

I have a requirement to remove a number of the default nodes (i.e. People and Groups, Sites) in the left hand current navigation bar using the SharePoint API. Can anyone give me any guidance on how to achieve this?

Thanks, MagicAndi

Best Answer

Your code will look something like this:

using (SPSite oSite= new SPSite("http://someurl/")){
    using (SPWeb oWeb = oSite.OpenWeb()){
        foreach (SPNavigationNode oNode in oWeb.Navigation.QuickLaunch)
        {
            if (oNode.Title == "Sites") {
                oNode.Delete();
            }
        }    
    }
}

be aware, though, that finding the item by title is not very recommended - it will differ if the web'b locale is not English. So it would be a better idea to find the node by its ID. See IDs here - http://msdn.microsoft.com/en-us/library/dd587301(office.11).aspx

Related Topic