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
Post a Comment