SharePoint 2013 Hosting :: How to Make Quick Launch Menu Programmatically

Quick Launch is navigation located on the left side of the screen and it is important part of almost every SharePoint site (marked in red square on the image).

How to Make Quick Launch Menu Programmatically

Links to the Quick Launch can be added manually in Site Settings, but, if you want to automate the process of adding the links, you can do it from c# code.

The code is very simple, it consists of reading the Quick Launch object, deleting the existing links in it. And then, after the existing Quick Launch is cleared, putting the new links which we have read from some text file.

C# CODE:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSiteCollection = new SPSite(“http://mySiteUrl”))
{
using (SPWeb oWeb = oSiteCollection.OpenWeb())
{
// Create the node.
SPNavigationNodeCollection _quickLaunchNav = oWeb.Navigation.QuickLaunch;
// Delete all existing items in Quick Launch
int _counter = 0;
while (_quickLaunchNav.Count != _counter && _quickLaunchNav.Count > 0)
{
_counter++;
SPNavigationNode _item = _quickLaunchNav[0];
_item.Delete();
}

// Here we read links that will go in Quick Launch from text file
// Let’s say that in “abc.txt” file we have links written as (title|link):
//
// My project |/sites/MyTestSite1
// Project documents|/sites/MyDocLib2
// Reports|/sites/MyCustomReports
//…

string _line;

System.IO.StreamReader _file = new System.IO.StreamReader(“abc.txt”);
while ((_line = _file.ReadLine()) != null)
{
string[] _splitStr = _line.Split(‘|’);
string _title = _splitStr[0];
string _url = _splitStr[1];

SPNavigationNode _SPNode = new SPNavigationNode(_title, _url, true);

_quickLaunchNav.AddAsLast(_SPNode);

}
_file.Close();
}
}
});

In my next post, I’ll show how to create custom links in Top Navigation of SharePoint.

Best SharePoint Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers SharePoint hosting starts from $9.99. We also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable SharePoint Hosting, we should be your best choice.