Set Audience for Quick Launch Navigation Links Programmatically


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Navigation;

namespace ConsoleOperations
{
    class TargetAudienceToNavigationNodes
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost:5030"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;
                    SPNavigationNode nodeHeader = new SPNavigationNode("TestNode", @"Lists/Tasks/AllItems.aspx", false);
                    SPNavigationNode node = new SPNavigationNode("TestNodeFirst", @"/Lists/Tasks/AllItems.aspx", false);
                    nodeHeader = nodeColl.AddAsLast(nodeHeader);
                    nodeHeader.Children.AddAsFirst(node);
                    node.Properties.Add("Audience", ";;;;GroupName");
                    node.Update();
                    web.Update();
                }
            }
        }
    }
}

We must specify the 4 colons (;) before group name....

Comments

Popular posts from this blog

javascript to get the all site user in sharepoint 2010 (Getting all Site users using Client Object Model)

Adding Navigation Links To Quick Launch Bar Programatically (SharePoint 2010)

Disable all day event, Recurrence,Workspace Fields in Calendar list