How to hide document library in SharePoint Online

In this SharePoint tutorial, we will discuss how to hide document library in SharePoint Online. We will see the below things:

  • Hide list from site contents SharePoint online
  • How to hide document library in SharePoint using SSOM (Server object model code)
  • Hide list from site contents SharePoint online using PnP PowerShell
  • How to hide list or library using PowerShell in SharePoint
  • Hide a document library in sharepoint online using SharePoint designer 2013

There is no out of box feature available in the browser to hide a list in SharePoint Online. So you can follow the below approach to hide a document library from Site Contents page in SharePoint.

Hide list from site contents in SharePoint Programmatically

We can easily hide the SharePoint list or document library using the SharePoint server object model code. Below is the code to hide the list or document library. You can write in a visual web part or in a feature in SharePoint 2010/2013/2016.

using (SPSite site = new SPSite(“http://SiteURL”))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[“MyList”];
list.Hidden = true;
list.Update();
}
}

Once you execute the code, MyList will not be visible in the Site Contents page in SharePoint. This way, we can also hide document library in SharePoint 2013/2016/2019.

Note: This code will not work in SharePoint Online.

Hide document library SharePoint online using SharePoint designer 2013

Now, let us see how to hide list from site contents sharepoint online using SharePoint designer 2013. The saw way, we can also hide document library SharePoint.

Follow the below steps to hide document library SharePoint online:

  1. For this Open the SharePoint site using SharePoint designer 2013/2010, then from the Site Objects click on Lists and Libraries.
  2. Then click on the particular list which you want to hide, This will open the settings home page.
  3. From the Settings page, from the General Settings, Check the check box “Hide from browser”.
hide document library sharepoint
hide document library sharepoint

Then Click on Save.

Now when opening the SharePoint site in the browser, the list will be hidden. This is how we can use SharePoint designer to hide a list in SharePoint.

Hide list or document library using PowerShell in SharePoint 2013/2016/2019

Now, let us see how to hide a list using PowerShell in SharePoint 2013, SharePoint 2016, or in SharePoint 2019.

In my current project client want to upload some of the confidential documents and wants to hide the library. Also, he wants to ensure that no user looks at the document though they navigate with a URL. Step1 I have implemented the below script to hide the document library from site contents in SharePoint 2013.

PowerShell Script to Hide List or Document Library in SharePoint 2016/2019

The below script is to hide the list/library in SharePoint 2016/2013. You can run debug and test PowerShell script using Windows PowerShell ISE.

function ShowOrHideListLibs($strSiteUrl, $strLstName, $boolHideValue)
{
try
{
#Get Web Object
$objWeb = Get-SPWeb $strSiteUrl
#Get the List Object
$objList = $objWeb.Lists[$strLstName]
#Set list / library the Hidden Property to show or hide
$objList.Hidden = $boolHideValue
$objList.Update()
Write-Host $strLstName + IIf ($showHideValue -eq $true) "Hidden successfully!" "Enabled/shown successfully!"
$objWeb.Dispose()
}
catch {
write-host "Could not find web" -foregroundcolor red
}
}

How it works?

Open PowerShell with run as administrator and run the script by providing the below 3 required parameters:

  • SharePoint Site URL
  • SharePoint Library Name
  • Flag bit value True -> To Hide the document library False -> To show the document library.

Syn:

  • ShowOrHideListLibs <<Site URL>> << List/Library Name>> << Flag bit value >>
  • #Send the parameters as site URL, List/Library name, $true — To Hide /$false — To Show
  • ShowOrHideListLibs “http://Sharepoint2013:12345/” “User Loan Reports” $true

This is how we can hide list from site contents in SharePoint onpremises versions.

Here, it is another PowerShell script to to hide list and libraries in SharePoint On-premise.

$siteUrl = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
$listName="MyTestList"
$web = Get-SPWeb $siteUrl
$list = $web.Lists[$listName]
$list.Hidden = $showHideValue
$list.Update()

Hide document library SharePoint Online using PowerShell

Now, let us see how to hide document library SharePoint Online using PowerShell.

The below script works for SharePoint Online:

#Including SharePoint Client side assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
#Reading User-ID and Password to connect SharePoint Online Site
$strUserId = Read-Host "Enter the username of SPO (eg. [email protected])"
$strPassword = Read-Host "Please enter the password for $($strUserId)" -AsSecureString
#Setup Credentials to connect
$ObjCreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($strUserId,$strPassword)
function ShowHideList($strSiteCollURL, $strLstName, $boolHidenVal)
{
#Bind to site collection
$ObjContext = New-Object Microsoft.SharePoint.Client.ClientContext($strSiteCollURL)
$ObjContext.Credentials = $ObjCreds
#Get the List
$ObjList = $ObjContext.Web.Lists.GetByTitle($strLstName)
$ObjList.Hidden = $boolHidenVal
$ObjList.Update()
$ObjContext.ExecuteQuery()
Write-Host $strLstName + IIf ($boolHidenVal -eq $true) "Hidden successfully!" "Enabled/shown successfully!"
}

Like as SharePoint online execution we can execute the same from SharePoint PowerShell window / you can install SharePoint online PowerShell on windows on your local machine and execute the script.

We can also use the PowerShell CSOM to hide document library in SharePoint Online.

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$siteUrl = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$credentials= Get-Credential
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credentials.Username, $credentials.Password)
$list = $context.Web.Lists.GetByTitle("MyTestList")
$list.Hidden = $true
$list.Update()
$context.ExecuteQuery()

Hide document library SharePoint online using PnP PowerShell

Now, let us see how to hide document library in SharePoint Online PnP PowerShell.

Below is the PowerShell script:

$listName = "MyTestList"
$siteURL = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
Connect-PnPOnline -Url $siteURL -UseWebLogin
Set-PnPList -Identity $listName -Hidden $true

You may like following SharePoint tutorials:

I hope this SharePoint tutorial explains, how to hide a list from site contents sharepoint online? or How to hide a document library SharePoint online.

>