how to hide links in sharepoint page

Bharathi Paulraj 21 Reputation points
2022-11-13T16:35:39.097+00:00

So many links(approximately 20 document library links) are there in one page of the sharepoint 2016 onpremise classic.links means from text to display and address finally added the text and url.I have to hide some links eventhough they are having the particular document library permissions also. using c# ho hide?

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

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-11-14T05:49:46.817+00:00

    Hi @Bharathi Paulraj
    Per my test, you can refer to following code to delete the links in sharepoint navigation.

    using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))  
    {  
    NavigationNodeCollection navigationNodes = null;  
       
    // Option 1: This will get quick launch collection from parent web  
    // This option will work only if the method is running from sub-site otherwise parent ID will be Null  
    clientcontext.Load(clientcontext.Web.ParentWeb, p => p.Id);  
       
    clientcontext.ExecuteQuery();  
    navigationNodes = clientcontext.Site.OpenWebById(clientcontext.Web.ParentWeb.Id).Navigation.QuickLaunch;  
       
    // Option 2: This will get quick launch collection from current site  
    navigationNodes = clientcontext.Web.Navigation.QuickLaunch;  
       
    clientcontext.Load(navigationNodes);  
    clientcontext.ExecuteQuery();  
       
    NavigationNode node = (from navigationNode in navigationNodes where "Navigation node name" == navigationNode.Title select navigationNode).FirstOrDefault();  
       
    // Condition to check the existence of the navigation node.  
    if (node != null)  
    {  
    node.DeleteObject();  
    clientcontext.ExecuteQuery();  
    }  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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. Bharathi Paulraj 21 Reputation points
    2022-11-15T15:08:00.26+00:00

    Hi RaytheonXie_MSFT
    Actually in my company 5 departments are there.So i have created 5 buttons(for ex. A,B,C,D,E).On click of A button i want to see in which document library and all A department people are having permission that links will come on that page.In that page 20 links(document library links) are there.If they are having permission in 5 document library in that page i should see only 5 links.remaining 15 links should be hide.Like that On click of B button in which document library and all B department people are having permission that links will come on that page.like that C,D,E.How to do using c#

    0 comments No comments

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.