当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何在 SharePoint 中的新按钮下拉列表中隐藏内容类型?

作者:精品下载站 日期:2024-12-14 14:35:45 浏览:14 分类:玩电脑

如何在 SharePoint 中的新按钮下拉列表中隐藏内容类型?


要求:从 SharePoint 中的新按钮下拉列表中隐藏内容类型。

如何在 SharePoint 中隐藏内容类型?

在 SharePoint 中,当您向库添加新内容类型时,它将添加到功能区的“新建”按钮下拉列表中。如果您想从“新建”按钮下拉列表中隐藏内容类型,请按以下步骤操作:

要从 SharePoint 的新菜单中隐藏内容类型,

  1. 转到该列表所在的 SharePoint Online 网站。
  2. 导航到列表>>单击设置>>列表设置>>在“内容类型”下,单击“更改新按钮顺序和默认内容类型”链接。

    [玩转系统] 如何在 SharePoint 中的新按钮下拉列表中隐藏内容类型?

  3. 通过取消选中刻度线将“Visible”标志设置为 False。您还可以更改新按钮顺序。

    [玩转系统] 如何在 SharePoint 中的新按钮下拉列表中隐藏内容类型?

这会隐藏 SharePoint 中的内容类型。

SharePoint PowerShell 隐藏内容类型

我们还可以使用 PowerShell 从 SharePoint 的新菜单中隐藏内容类型。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set config variables
$WebURL="https://intranet.crescent.com/"
$ListName ="Projects"
$ContentTypeName="Project Template"

#Get Web and Objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]

#Get the content type
$ContentType = $List.ContentTypes[$ContentTypeName]
$ContentType.Hidden = $True
$ContentType.Update()

Write-Host "Content Type Hidden from the List!"

这会从新菜单下拉列表中隐藏内容类型。

SharePoint Online:使用 PowerShell 隐藏内容类型下拉列表

同样,要隐藏 SharePoint Online 中的内容类型,我们可以使用以下 PowerShell 脚本:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ListName="Contacts"
$ContentTypeName="Business Contacts"

Try {
    #Get Credentials to connect
    $Cred= Get-Credential

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        
    #Get the content type from the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
 
    #Get the content type from list
    $ContentTypeColl = $List.ContentTypes
    $Ctx.Load($ContentTypeColl)
    $Ctx.ExecuteQuery()
 
    #Get the content type to Hide
    $CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
    If($CType -ne $Null)
    {
        $CType.Hidden=$True
        $CType.Update($False)
        $Ctx.ExecuteQuery()

        Write-host "Content Type is Set to Hidden!" -ForegroundColor Green
    }
    else
    {
        Write-host "Content Type Doesn't Exist!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Setting Conent Type to Hidden!" $_.Exception.Message
}

PnP PowerShell 在 SharePoint Online 列表中隐藏内容类型:

以下是如何从 SharePoint Online 的新下拉列表中隐藏内容类型。


$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Contacts"
$ContentTypeName ="Business Contacts V2"

#Connect to Pnp Online
Connect-PnPOnline -Url $SiteURL -Interactive
 
#Get the Context
$Context = Get-PnPContext
 
#Get the content type from List
$ContentType = Get-PnPContentType -Identity $ContentTypeName -List $ListName
 
#Set content type to hidden
$ContentType.Hidden = $True
$ContentType.Update($False)
$Context.ExecuteQuery()

在 SharePoint 列表中隐藏内容类型不会从网站集或使用该内容类型的任何其他列表中删除该内容类型。如果要从网站集完全删除内容类型,则必须将其从网站集内容类型库中删除。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯