The SPNavigationNode.IsVisible property does not work in sharepoint as expected

I want to hide the quick start of node on the sharepoint site, but it does not work properly. :(

My code looks like this:

                using (SPSite spSiteTest = new SPSite(serverUrl))
                {

                    using (SPWeb mySite = spSiteTest.OpenWeb())
                {
                    SPNavigationNodeCollection quickLaunchNodes = mySite.Navigation.QuickLaunch;

                    SPNavigationNode navQuickNode = new SPNavigationNode("Title", "www.stackoverflow.com", true);


                    foreach (SPNavigationNode node in quickLaunchNodes)
                    {
                        if (node.Title == navQuickNode.Title)
                        {
                            node.Url = navQuickNode.Url;
                            node.IsVisible = isVisible;
                            node.Update();
                            //mySite.Update();
                            return;
                        }
                    }   

                    quickLaunchNodes.AddAsFirst(navQuickNode);

                }
            }

Am I missing something or is this a mistake?

+3
source share
2 answers

You can delete nodes as follows:

node.Delete();
mySite.Update();

or check the method ExcludeFromNavigationmentioned in this post (its author assumes that it was not possible to hide the node navigation on the installation IsVisiblein is falsealso a SharePoint error).

+1
source

Show / hide navigation nodes using the SharePoint Server Side Object Model (SSOM)

PortalNavigation Class :

< >

:

using (var site = new SPSite(siteUrl))
{
    using (var web = site.OpenWeb())
    {
        var subWeb = web.Webs["Announcements"];

        var publishingWeb = PublishingWeb.GetPublishingWeb(web);
        publishingWeb.Navigation.ExcludeFromNavigation(false,subWeb.ID);
        publishingWeb.Update();

    }
}

/ SharePoint (CSOM)

SharePoint CSOM.

SharePoint 2013:

SharePoint 2013 Microsoft.SharePoint.Client.Publishing Microsoft.SharePoint.Client.Publishing.Navigation CSOM API. , , WebNavigationSettings, .

CSOM ClientPortalNavigation.cs, CSOM SSN PortalNavigation. SharePoint .

< >

:

using (var ctx = new ClientContext(webUri))
{

     //Get page file
     var pageFile = ctx.Web.GetFileByServerRelativeUrl("/news/Pages/Announcements.aspx");
     ctx.Load(pageFile);
     ctx.ExecuteQuery();

     //Hide page from Global navigation
     var navigation = new ClientPortalNavigation(ctx.Web);
     navigation.ExcludeFromNavigation(true, pageFile.UniqueId);
     navigation.SaveChanges();
 }

:

 using (var ctx = new ClientContext(webUri))
 {

     //Get sub site
     var result = ctx.LoadQuery(ctx.Web.Webs.Where(w => w.Title == "Archive"));
     ctx.ExecuteQuery();
     var subWeb = result.FirstOrDefault();

     //Hide web from Global navigation
     var navigation = new ClientPortalNavigation(ctx.Web);
     navigation.ExcludeFromNavigation(true, subWeb.Id);
     navigation.SaveChanges();
 }
0

Source: https://habr.com/ru/post/1740807/


All Articles