Good Morning All, I'm running into an issue where I would like to hide and show links on the quick launch based on a specific SharePoint group. I know how you can do it through the browser, but I'm to do it through code, either through a feature or master page. I do have publishing enabled which allows me to configure both the global and quick launch navigation. My first attempt was to set the "Audience" on link based on a specific SharePoint group (See code below)
SPNavigation spSiteNav = spWeb.Navigation;
SPNavigationNodeCollection spSiteQuickLaunch = spSiteNav.QuickLaunch;
SPNavigationNode spBaseHeading = spWeb.Navigation.QuickLaunch.Cast<SPNavigationNode>().Where(a => a.Title == "I need to").FirstOrDefault();
if (spBaseHeading != null){
string webAppRelativePath = spWeb.ServerRelativeUrl;
if (!webAppRelativePath.EndsWith("/")){ webAppRelativePath += "/";}
string MemPageUrl = string.Format("{0}{1}", webAppRelativePath, "SitePages/CreateNewMemo.aspx");
SPNavigationNode MemoPageLink = spBaseHeading.Children.Cast<SPNavigationNode>().Where(a => a.Url == MemPageUrl).FirstOrDefault();
MemoPageLink.Properties["Audience"] = string.Format(";;;;{0}", "Authors");
MemoPageLink.Update();
}
No luck, the code sets the audience on the link, but non "Authors" members can still see the link on the quick launch.
Then I tried setting the IsVisible property (See code below):
SPNavigation spSiteNav = spWeb.Navigation;
SPNavigationNodeCollection spSiteQuickLaunch = spSiteNav.QuickLaunch;
SPNavigationNode spBaseHeading = spWeb.Navigation.QuickLaunch.Cast<SPNavigationNode>().Where(a => a.Title == "I need to").FirstOrDefault();
if (spBaseHeading != null){
string webAppRelativePath = spWeb.ServerRelativeUrl;
if (!webAppRelativePath.EndsWith("/")){webAppRelativePath += "/";}
string MemPageUrl = string.Format("{0}{1}", webAppRelativePath, "SitePages/CreateNewMemo.aspx");
SPNavigationNode MemoPageLink = spBaseHeading.Children.Cast<SPNavigationNode>().Where(a => a.Url == MemPageUrl).FirstOrDefault();
MemoPageLink.IsVisible = false;
MemoPageLink.Update();
}
No luck again. The property is set, but the link is still visible to non "Authors" members.
I'm lost, any help would be greatly appreciate.
Thank you in advance....