Mysterious link in QuickLaunch

Antti Mikkonen 96 Reputation points
2020-09-25T09:59:49.91+00:00

I'm trying to remove a link to the publishing page created by the PNP provisioning template. Link is visible in the site's navigation but when trying to delete it with CSOM code the link is not included in Navigation.Quicklaunch.

I have also tested powershell:

$web = Get-SPWeb mysitesurl
$web.Navigation.QuickLaunch

The link cannot be found in this way either.

Link can be manually hided from the navigation with editing the left navigation or from the address _layouts/15/AreaNavigationSettings.aspx
If I edit left navigation from the UI my missing link is then accessible through code and powershell. Any ideas why this is happening and how it can be fixed programmatically?

Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Accepted answer
  1. Antti Mikkonen 96 Reputation points
    2020-09-29T17:27:41.703+00:00

    Managed to get desired results with removing all pages and subsites from navigation.

    web.AllProperties["__CurrentNavigationIncludeTypes"] = 0;
    

    Still the cause of this mysterious functionality still remains.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-09-28T01:51:58.243+00:00

    My test code for your reference,it works well in my environment:

    using (ClientContext clientContext = new ClientContext("http://sp"))  
                {  
                    NavigationNodeCollection navigationNodes = null;                         
                    navigationNodes = clientContext.Web.Navigation.QuickLaunch;      
                    clientContext.Load(navigationNodes);  
                    clientContext.ExecuteQuery();  
                    NavigationNode node = navigationNodes.Where(n => n.Title == "List Title").FirstOrDefault();                      
                    if (node != null)  
                    {  
                        node.DeleteObject();  
                        clientContext.ExecuteQuery();  
                    }  
                }  
    

    If you have any update on this issue,please feel free to share with us.

    -----------------------------------------
    Updated------------------------------------
    JavaScript code hide quick launch item:code.txt


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Antti Mikkonen 96 Reputation points
    2020-09-29T14:34:00.447+00:00

    Yes, that's absolutely code that works, but only one page exists on my quicklaunch that cannot be found from the navigationNodes.

    That problem might my somehow related how the page is provisioned...

    The problematic link has a different icon than others. Is this the reason?
    29192-quicklaunch.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.