none
Read Quick Launch items programmatically RRS feed

  • Вопрос

  • This is the code I'm using:

    using (SPSite site = new SPSite(siteUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPNavigationNodeCollection _quickLaunchNav = web.Navigation.QuickLaunch;

    }

    }

    The problem:

    in the _quickLaunchNav variable, I get 63 items, but my Quick Launch has on 12 on GUI.

    Same thing is when I go to any subsite, I get too many navigation items. How can I filter them to get the exact number of quick launch items as defined on the GUI?

    Edit: If it is important, it is a publishing site.

    Edit2:

    When using this:

    var pubWeb = PublishingWeb.GetPublishingWeb(web);                   
    pubWeb.Navigation.CurrentNavigationNodes

    I get 62 items, but when I use this:

    var pubWeb = PublishingWeb.GetPublishingWeb(web);                 
    pubWeb.Navigation.GlobalNavigationNodes

    I get 50 items.

    How can I exclude each other and get to my 12 items??

    • Изменено Mario Zagreb 18 октября 2019 г. 22:53
    18 октября 2019 г. 21:11

Все ответы

  • Hi Mario,

    Could you please try this code-

     using (SPWeb xWeb = siteCollection.OpenWeb())
                    {
                        //Add the library to quick launch
                        SPNavigationNodeCollection nodes = xWeb.Navigation.QuickLaunch;
                        for (int i = 0; i < nodes.Count; i++)
                        {
                            if (nodes[i].IsVisible == true)
                            {
                 
                                
                            }
                        }
    
                        Console.ReadKey();
                    }


    K Mohit

    20 октября 2019 г. 15:30
  • Hi Mario,

    Please check the code below.

    var siteUrl = "http://sp2013/sites/team";                         
    using (SPSite site = new SPSite(siteUrl))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    		foreach (SPNavigationNode nav in web.Navigation.QuickLaunch)
    		{
    			if (nav.IsVisible)
    			{
    				Console.WriteLine(nav.Title);
    				foreach (SPNavigationNode cnav in nav.Children)
    				{
    					if (nav.IsVisible)
    					{
    						Console.WriteLine("  "+cnav.Title);
    					}
    				}
    			}
    		}                  
    	}
    }

    If the current navigation are not include the sub sites, please using the code below.

    var siteUrl = "http://sp2013/sites/team";                         
    using (SPSite site = new SPSite(siteUrl))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    		foreach (SPNavigationNode nav in web.Navigation.QuickLaunch)
    		{
    			if (nav.IsVisible&&nav.TargetParentObjectType.ToString()!="Web")
    			{
    				Console.WriteLine(nav.Title);
    				foreach (SPNavigationNode cnav in nav.Children)
    				{
    					if (nav.IsVisible)
    					{
    						Console.WriteLine("  "+cnav.Title);
    					}
    				}
    			}
    		}                  
    	}
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    • Изменено Dennis GuoModerator 21 октября 2019 г. 8:33
    • Предложено в качестве ответа KumarMohiT 21 октября 2019 г. 10:11
    • Отменено предложение в качестве ответа Mario Zagreb 21 октября 2019 г. 14:22
    21 октября 2019 г. 8:33
    Модератор
  • No, the result is always the same; 63 items.
    • Изменено Mario Zagreb 21 октября 2019 г. 9:29
    21 октября 2019 г. 9:29
  • Hi Mario,

    Please provide more information about your navigation settings(go to Site settings->Look and Feel->Navigation).

    And provide some screenshots for further research.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    22 октября 2019 г. 9:52
    Модератор
  • Hi Mario,

    Would you please provide us with an update on the status of your issue?

    Best Regards,
    Dennis

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    28 октября 2019 г. 8:24
    Модератор