Friday, March 19, 2010

C# Programmatically Set audiance permissions for Sharpoint Quick launch bar

To add the links in the left navigation first we need to get all links in the quick launch bar using SPNavigationCollection class

SPWeb web = SPContext.Current.Web;
SPNavigationCollection coll = web.Navigation.QuickLaunch;

/* With SPNavigationNode class we are adding our custom links(Node) in the quick launch bar */

SPNavigationNode node = new SPNavigation(linkTitle,url,true);
/*Add the node as root in the quick launch bar*/
web.AllowUnSafeUpdates = true;
coll.AddAsFirst(node);
/*Give permissions to the link*/
node.Properties.Add("Audiance",";;;;","groupName or UserName");
node.Update();

/* Creating sub links under main links in quick launch bar */
SPNavigation subnode = new SPNavigation(linkSubTitle, subUrl,true);
node.Children.AddAsLast(subNode);
/* Providing permssions to sub links in quick launch */
subNode.Properties.Add("Audiance",";;;;","group or username");
subNode.Update();
web.AllowUnSafeUpdates = false;

thats all !!!!