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


  • 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,"",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:

    Hope it could help

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

    Wednesday, August 22, 2012 9:00 AM