ARTICLE

Quick Launch Navigation in SharePoint 2010: Part1

Posted by Vijai Anand Articles | SharePoint 2010 March 28, 2011
In this article we will be seeing how to manage the Quick Launch Navigation in SharePoint 2010 using PowerShell and SharePoint Object Model.
Reader Level:

In this article we will be seeing how to manage the Quick Launch Navigation in SharePoint 2010 using PowerShell and SharePoint Object Model.

Get all the Headings and Links from the Quick Launch:

Using C#:

using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;
                    foreach (SPNavigationNode heading in nodeColl)
                    {
                        Console.WriteLine(heading.Title.ToString());

                        foreach (SPNavigationNode links in heading.Children)
                        {
                            Console.WriteLine("-" + links.Title.ToString());
                        }                       
                    }
                    Console.ReadLine();
                }
            }

Output:

Share1.gif

Using PowerShell:

$siteURL="http://serverName:1111/sites/SPSiteDataQuery/"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$navigationNodeColl=$web.Navigation.QuickLaunch
foreach($heading in $navigationNodeColl)
{
write-host -f Green $heading.Title
foreach($links in $heading.Children)
{
write-host -f Yellow $links.Title
}
}

Output:

Share2.gif

Move the Headings in the Quick Launch:

In this we will be seeing how to move the headings in the Quick Launch Navigation. Initially Quick Luanch Navigation looks like the following.

Share3.gif

MoveToLast and MoveToFirst Methods:

using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;
                    foreach (SPNavigationNode heading in nodeColl)
                    {
                        if (heading.Title.ToString() == "Libraries")
                        {
                            heading.MoveToLast(nodeColl);
                        }
                        if (heading.Title.ToString() == "Lists")|
                        {
                            heading.MoveToFirst(nodeColl);
                        }                 
                    }                  
                }
            }

Share4.gif

Move Method:

using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;
                    SPNavigationNode heading = nodeColl[0];
                    heading.Move(nodeColl, nodeColl[1]);
                }
            }


Share5.gif

Login to add your contents and source code to this article
post comment
     

Is it possible to move a link between parent headers? What I have is for exampleLists -Custom List 1 -Custom List 2 -Calendar Libraries -Shared DocumentsWhat I want to do is create a header with no URL, I figured that part out, and then move list under the new headers. So I end up with soemthing like this.Resources -Custom List 2 Company Data -Custom List 1 -Canlendar Libraries -Shared DocumentsHow can I do that.

Posted by Karen Jun 27, 2012
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter