1

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

1 Answer 1

2

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();
        }
    }
5
  • 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. Apr 27, 2011 at 14:48
  • Global and current work the same as far as I know. I have used this for current as well. Apr 27, 2011 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. Apr 27, 2011 at 17:17
  • Sorry forgot the update line. Added navNode.Update() Apr 27, 2011 at 19:34
  • Did this solve your issue? if so would you mind marking it as answered? Apr 28, 2011 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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