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 2019년 10월 18일 금요일 오후 10:53
    2019년 10월 18일 금요일 오후 9: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

    2019년 10월 20일 일요일 오후 3: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 2019년 10월 21일 월요일 오전 8:33
    • 답변으로 제안됨 KumarMohiT 2019년 10월 21일 월요일 오전 10:11
    • 답변으로 제안 취소됨 Mario Zagreb 2019년 10월 21일 월요일 오후 2:22
    2019년 10월 21일 월요일 오전 8:33
    중재자
  • No, the result is always the same; 63 items.
    • 편집됨 Mario Zagreb 2019년 10월 21일 월요일 오전 9:29
    2019년 10월 21일 월요일 오전 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.

    2019년 10월 22일 화요일 오전 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.

    2019년 10월 28일 월요일 오전 8:24
    중재자