Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can i add the new link as well as set the audience in currentNavSiteMapProvider in SharePoint Publishing using SharePoint Object Model.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I have used this method

public void SetNavigation()
    {
        using (SPSite Site = new SPSite("http://YourWeb"))
        using (SPWeb Web = Site.OpenWeb())
        {
            SPNavigationNode navNode = Web.Navigation.GlobalNodes[0];

            if (navNode.Properties.Contains("Audience"))
            {
                navNode.Properties["Audience"] = ";;;;YourSiteMembers,YourSiteOwners";
            }
            else
            {
                navNode.Properties.Add("Audience", ";;;;YourSiteMembers,YourSiteOwners");
            }
            navNode.Update();
        }
    }
share|improve this answer
    
Thanks @David, I just wanted to confirm that I wanted to add the links in Current navigation not in GlobalNodes. Is this code work for SharePoint Current navigation. –  Basant B. Pandey Apr 27 '11 at 14:48
    
Global and current work the same as far as I know. I have used this for current as well. –  David Palfery Apr 27 '11 at 15:03
    
I test the above code but I am unable to get the values audience properties. FYI I am getting the properties like "vti_nonnavpage" ect. –  Basant B. Pandey Apr 27 '11 at 17:17
    
Sorry forgot the update line. Added navNode.Update() –  David Palfery Apr 27 '11 at 19:34
    
Did this solve your issue? if so would you mind marking it as answered? –  David Palfery Apr 28 '11 at 20:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.