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

[玩转系统] SharePoint Online 列表视图中的按内容类型分组

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

SharePoint Online 列表视图中的按内容类型分组


要求:在 SharePoint Online 中按内容类型设置列表视图组。

如何按内容类型设置 SharePoint Online 视图组?

如果您想根据“内容类型”设置列表视图的分组依据选项,则 Web 界面中没有选项(因为下拉列表中的列列表中缺少“内容类型”!)。以下是按内容类型分组的方法。

选项 #1:使用 SharePoint Designer 编辑 ListView

以下是使用 SharePoint Designer 设置组的方法:

  1. 从 SharePoint Web 用户界面创建列表视图
  2. 使用 SharePoint Designer 在高级模式下编辑视图页面。 搜索“”并将其替换为:

<Query>
       <GroupBy Collapse='FALSE' GroupLimit='30' >
             <FieldRef Name='ContentType' />
       </GroupBy>
</Query>

[玩转系统] SharePoint Online 列表视图中的按内容类型分组

此方法也适用于本地 SharePoint。

选项#2:使用 PowerShell 在 SharePoint Online 中按“内容类型”进行分组

在 SharePoint Online 列表中创建列表视图,并使用此 PowerShell CSOM 脚本通过“ContentType”字段更新列表视图的组。


#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"
 
#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$ListName ="Documents"
$ViewName="All Documents"
 
Try {
    #Setup Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
    
    #Get the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)

    #Get the view to update
    $View = $List.Views.GetByTitle($ViewName)
    $Ctx.ExecuteQuery()

    if($View -ne $NULL)  
    {
        #Define the CAML Query to Group by Content Type 
        $Query= "<GroupBy Collapse='FALSE' GroupLimit='30' ><FieldRef Name='ContentType' /></GroupBy>"

        #Update the View
        $View.ViewQuery = $Query
        $View.Update()
        $Ctx.ExecuteQuery()

        Write-host "View Updated Successfully!" -f Green
    }
    else
    {
        Write-host "View '$ViewName' Doesn't exist in the List!"  -f Yellow
    }
}
Catch {
    write-host -f Red "Error Updating List View!" $_.Exception.Message
}

这将根据内容类型对列表视图中的项目进行分组。

现代列表还有另一个技巧:将“?groupBy=ContentType”附加到视图 URL 并在浏览器中按 Enter 键,然后使用“将视图另存为”创建一个按内容类型分组的新视图!

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

取消回复欢迎 发表评论:

关灯