There are some scenarios where the document libraries on SharePoint are used only to upload files. For example, let’s say that you have a sales team that need to upload to a document library an excel every week. Therefore, maybe the new button to have an option to create a new folder or create a new document doesn’t make much sense.
So, if click on that button as admin of the SharePoint site and there is an option that allows you to edit that menu. If you remove all the option allow you to hide that menu which is exactly what we want. But let’s say that you need to apply that to multiple sites, you need to automate probably using Powershell. So we gonna use PnP PowerShell to configure that option.
# If you want to change between some option and other
# change visibility to true or false on the function DefaultMenuItems
$list = "Documents"
$siteUrl = "https://contoso.sharepoint.com/sites/siteToChange"
$iconVisibility = $true
function Add-MenuItem {
param(
[Parameter(Mandatory)]$title,
[Parameter(Mandatory)]$visible,
[Parameter(Mandatory)]$templateId
)
$newChildNode = New-Object System.Object
$newChildNode | Add-Member -type NoteProperty -name title -value $title
$newChildNode | Add-Member -type NoteProperty -name visible -value $visible
$newChildNode | Add-Member -type NoteProperty -name templateId -value $templateId
return $newChildNode
}
function Get-DefaultMenuItems {
$DefaultMenuItems = @()
$DefaultMenuItems += Add-MenuItem -title "Folder" -templateId "NewFolder" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "Word document" -templateId "NewDOC" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "Excel workbook" -templateId "NewXSL" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "PowerPoint presentation" -templateId "NewPPT" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "OneNote notebook" -templateId "NewONE" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "Visio drawing" -templateId "NewVSDX" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "Forms for Excel" -templateId "NewXSLForm" -visible $iconVisibility
$DefaultMenuItems += Add-MenuItem -title "Link" -templateId "Link" -visible $iconVisibility
return $DefaultMenuItems
}
Connect-PnPOnline -Url $siteUrl -UseWebLogin
$list = Get-PnpList -Identity $ListTitle
$defaultView = Get-PnpView -List $List | Where-Object { $_.DefaultView -eq $true }
$MenuItems = Get-DefaultMenuItems
$defaultView.NewDocumentTemplates = $MenuItems | ConvertTo-Json
$defaultView.Update()
Invoke-PnPQuery
Conclusion
The SharePoint where you made this configuration will show or hide the Button. You can for instance apply this to a SharePoint Hub or to a list of SharePoint site.
If you need to add your own New option on this button, verify the following link:
[…] Show/hide the New button from a SharePoint Document Library […]
If all the content-types have been unchecked when editing the New button, the button disappears as noted above. How would you re-enable the content-types so that the New button is once again displayed?
Hi Sean,
On the DefaultMenuItems function, you need to make the visibility option to true.
I’ve updated the script shared on the blog post to include on top the property iconVisibility that allow you to set it to show the button when is $true and to hide when is $false.
My best,
David Ramalho