The estimated reading time for this post is 2 minutes
I’m sure removing the Recent heading from the Quick Launch in SharePoint 2013 has been talked about a million times over since SharePoint 2013 was launched. It’s been solved in this way and that way, by hand, with javascript and programmatically. In this post, I share the code to remove the heading with the ListAdded event receiver.
Event receiver code
It’s based on code provided as an answered on the SharePoint StackExchange website by Remko van Laarhoven. I’ve then wrapped in a list added event receiver so that it is executed each time a new list or library is added. As the list/library is then not available on the Quick Launch I’ve added a couple of lines to then show it.
[code language="c"]
System.Threading.Thread.Sleep(1500);
[code language="js"]
// Hide Recent on Quick Launch
$("#ctl00_PlaceHolderLeftNavBar_QuickLaunchNavigationManager .ms-core-listMenu-root li:contains('Recent')").children().remove();
$("#ctl00_PlaceHolderLeftNavBar_QuickLaunchNavigationManager .ms-core-listMenu-item:contains('Recent')").remove();
[code language="c"]
public class ListAddedEventReceiver : SPListEventReceiver
{
public override void ListAdded(SPListEventProperties properties)
{
base.ListAdded(properties);
SPWeb web = properties.Web;
if (web != null)
{
//Sleep
System.Threading.Thread.Sleep(1500);
//Remove heading
var title = SPUtility.GetLocalizedString("$Resources:core,category_Recent", null, web.Language);
SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;
foreach (SPNavigationNode node in nodes)
{
if (node.Title.ToLower().Equals(title.ToLower()))
{
// Delete the recent heading node
node.Delete();
break;
}
}
// Show list on the quick launch
SPList list = web.Lists[properties.ListId];
list.OnQuickLaunch = true;
list.Update();
}
}
}
Download Remove Recent Heading Solution
For those who don’t want to create the event receiver themselves in Visual Studio or don’t know how to, I have a packaged the solution so that you can deploy the WSP to your environment. For those who don’t know how to use this code, I will write a post explaining how to create this event receiver using Visual Studio from an IT Pros perspective very soon.
jcallaghan.removerecentheading.wsp
As with anything you download from the internet remember to review, rename and test this code/solution before using it in a production environment.
Leave a Reply
You must be logged in to post a comment.