SharePoint - 您如何使用PowerShell实际应用组合外观



有许多文章解释了如何创建 SharePoint 组合外观。他们还声称应用了上述组合外观,但他们实际上只是应用了调色板主题。

使用 SPWeb.ApplyTheme(( 应用主题不会应用母版页(仅应用调色板/字体/徽标(。

有没有办法使用 Powershell 或 C# 应用组合主题?

我已经成功应用了一个调色板(使用ApplyTheme((和母版页(使用MasterUrl/CustomMasterUrl(,但是当我转到"更改外观"时,它并不表示选择了正确的组合主题(它显示默认蓝色已选择(。

你对

你的发现是绝对正确的,我也遇到了同样的事情。本质上,您需要更新"当前"组合外观,以匹配通过 ApplyTheme(( 和 MasterUrl/CustomMasterURL 应用的合成外观的字段值:

#Set URL variables
$urlForSite = "https://YourSharePointSite/sites/test"
$themeUrl = "/sites/test/_catalogs/theme/15/YourTheme.spcolor"
#Get the site
$site = Get-SPSite $urlForSite
$relativeUrl = $site.ServerRelativeUrl
if ($relativeUrl -eq "/") {
    $relativeUrl = "" #make sure it doesn't end in a slash
}
#Update the "Current" entry if there is one
$designList = $site.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::DesignCatalog)
$camlQ = New-Object Microsoft.SharePoint.SPQuery
$camlQ.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Current</Value></Eq></Where>"
$items = $designList.GetItems($camlQ)
if ($items.Count -eq 1) {
    $item = $items[0]
    $item["MasterPageUrl"] = $relativeUrl + "/_catalogs/masterpage/seattle.master"
    $item["ThemeUrl"] = $themeUrl
    #Include these if you need to
    #$item["ImageUrl"] = ?
    #$item["FontSchemeUrl"] = ?
    $item.Update()
}
#Dispose because you know you should
$site.Dispose()

我还发现,当您通过UI中的"更改外观"选项应用组合外观时,在生成预览时/之后,它似乎使用DesignPreviewSaveData类:https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.utilities.designpreviewsavedata_properties.aspx

生成此预览时,有两个属性将添加到 SPWeb 的属性包中:

  • DesignPreviewLayoutUrl
  • 设计预览主题Css文件夹网址

发现我不需要更新这些属性,但您可能只想执行与 UI 进程相同的步骤。

最新更新