none
How to set Target Audience to Global navigation link programatically RRS feed

  • Question

  • I wants to create Global navigation links. Also wants to set target audience for this links. I am having shrepoint 2010 group. How do i set target audience to this links programmatically.

    Thanks in advance.

    Wednesday, August 22, 2012 8:46 AM

Answers

  • Hi,

    You can try below code:

    using (SPSite site = new SPSite(siteurl))
    {
    using (SPWeb web = site.OpenWeb())
    {
    if (web.IsRootWeb)
    {
    // Get the top link bar.
    SPNavigationNodeCollection topnav = web.ParentWeb.Navigation.TopNavigationBar;
    string linkName = "MSDN"; -> Adding link title as Link
    // Create the node.
    SPNavigationNode node = new SPNavigationNode(linkName,"http://www.msdn.com",true);
    node.AddAudience(new SPNavigationNodeAudience("Owners of site", AudienceType.SharePointGroup));
    node.AddAudience(new SPNavigationNodeAudience("Members of site", AudienceType.SharePointGroup));
    
    node = topnav.AddAsLast(node);
    }
    }
    }

    Check this similar thread for more info: http://social.technet.microsoft.com/Forums/nl/sharepoint2010programming/thread/d579d969-b8ee-4e62-adc8-5dea51520b38

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Wednesday, August 22, 2012 9:00 AM
    Moderator