3

I see you can make a list hidden by using SharePoint Designer (http://www.sharepointdiary.com/2013/06/how-to-hide-list-or-library-in-sharepoint.html) which I am not interested in.

It is okay if the list is available via the URL.

1
  • Are you trying to hide the list from specific people or everyone? If it's specific people, why not just remove permissions for those people from the list. Then they won't be able to see it on "All site content" view. Commented Apr 11, 2016 at 19:26

2 Answers 2

3

Try this

var list = ctx.Web.Lists.GetByTitle(listTitle);
list.Hidden = true;
list.Update();
ctx.ExecuteQuery(); 

Source: Hide document library using CSOM

Note that in the source they use BreakRoleInheritance to prevent users from accessing the list.

3
  • 1
    I don't think your code will do anything, as the default value for Hidden should be false. But using true will hide the list (while still letting it be accessible with a direct link).
    – eirikb
    Commented Apr 11, 2016 at 19:33
  • 1
    The question has a number of javascript tags, this answer is for the C# CSOM instead of the JavaScript JSOM - the answers will certainly be similar but not the same (there is no ExecuteQuery in JSOM)
    – John-M
    Commented Apr 11, 2016 at 19:40
  • Correct you can see Matt answer in JS Commented Apr 11, 2016 at 19:51
1

Thanks for everybody's responses. Close to jpussacq's question I was able to get it working by using the lists hidden attribute by using the set_hidden(true) in the following way:

//JSOM example
 ExecuteOrDelayUntilScriptLoaded(hideListItem, "sp.js");

  function hideListItem(){ 
  var ctx = new SP.ClientContext().get_current();

  var thisList  = ctx.get_web().get_lists().getByTitle('My List');

  thisList.set_hidden(true);
  //must be updated before loading
  thisList.update();

  ctx.load(thisList);

  ctx.executeQueryAsync(function(){



  });

}
2
  • 1
    I don't think you need to call ctx.load.
    – eirikb
    Commented Apr 11, 2016 at 19:59
  • 2
    And remember that the content in lists with hidden = true will not be crawled Commented Apr 11, 2016 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.