From the beginning Theme in SharePoint is an interesting feature for developer and UI designer. In WSS3.0 and MOSS 2007 all themes related files resides under theme folder inside 12 hives. So if you want to create new theme then you have to make new folder under theme and use it. So it was deployment directly on the file system and they could be available to other web applications even though they were not needed. And also after every change you need to deploy it and IIS reset was needed to take complete effect. So to remove those headache of deployment process Microsoft introduces Theme gallery in SharePoint 2010 and .thmx file. It actually was an answer to theme deployment(in 2007) with simple deployment approach in 2010(no need of IIS reset also); and also somehow it took away burden of creating theme from the SharePoint developer. But the problem with .thmx file was the resource needs to be PowerPoint expert to create those thmx files(I am not sure about other tools :)). At last in SharePoint 2013 it makes easy to make and apply theme; it makes clear two roles and their responsibilities: SharePoint UI Designer- he/she has to create the theme and SharePoint Developer/Admin – he/she has to deploy and apply the theme. Deployment process is also simple; you can have preview available to check how your site going to look. So life in SharePoint 2013 is little bit easy for developers :).
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue; [xml]$inputfile = Get-Content C:\Data\theme\ThemeScriptInput.xml $ColorFilePartUrl = "/_catalogs/theme/15/"; $FontFilePartUrl = "/_catalogs/theme/15/"; $MasterPagePartUrl = "/_catalogs/masterpage/"; foreach( $site in $inputfile.SiteCollections.site) { $siteurl = $site.url; $themeName = $site.theme; $colorfile = $site.colorfile; $fontfile = $site.fontfile; $masterpage = $site.masterpage; $colorshemeFilePath = $site.colorFilePath; $colorfontFilePath = $site.fontFilePath; $IsfilesToUpload = $site.filesToUpload; Write-Host "$siteurl + " :: " + $themeName + " :: " + $colorfile + " :: " + $fontfile + " :: " + $masterpage"; $site = Get-SPSite $siteurl; $rootweb = $site.RootWeb; if($IsfilesToUpload -eq "true") { #region Upload theme files to the root web gallery $colorSchemeBytes = [System.IO.File]::ReadAllBytes($colorshemeFilePath); $fontSchemeBytes = [System.IO.File]::ReadAllBytes($colorfontFilePath); $rootweb.allowunsafeupdates = $true; $themeList = $rootweb.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::ThemeCatalog); $folder = $themeList.RootFolder.SubFolders["15"]; $folder.Files.Add($colorfile,$colorSchemeBytes,$true); $folder.Files.Add($fontfile,$fontSchemeBytes, $true); $rootweb.allowunsafeupdates = $false; #endregion } $colorfile=$site.AllWebs[0].GetFile("$siteurl$ColorFilePartUrl$colorfile"); $fontfile=$site.AllWebs[0].GetFile("$siteurl$FontFilePartUrl$fontfile"); foreach ($Web in $site.AllWebs) { Write-Host "processing: " $Web.Title; $Web.allowunsafeupdates = $true; $relativeUrl = $Web.ServerRelativeUrl; $spList = $Web.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::DesignCatalog); #region Add New theme to the Composed Looks gallery $SPQuery1 = New-Object Microsoft.SharePoint.SPQuery; $SPQuery1.Query = "<Where><Eq><FieldRef Name='Name'/><Value Type='Text'>$themeName</Value></Eq></Where>"; $SPQuery1.RowLimit = 1; $SPQuery1.ViewFields = "<FieldRef Name='Name'/>"; $SPQuery1.ViewFieldsOnly = $true; $spListItems1 = $spList.GetItems($SPQuery1); if($spListItems1.Count -eq 0) { $newThemeItem = $spList.AddItem(); $newThemeItem["Name"] = $themeName; $newThemeItem["Title"] = $themeName; $newThemeItem["MasterPageUrl"] = "$relativeUrl$MasterPagePartUrl$masterpage";#$Web.MasterUrl; $newThemeItem["ThemeUrl"] = "$ColorFilePartUrl$colorfile"; $newThemeItem["FontSchemeUrl"] = "$FontFilePartUrl$fontfile"; $newThemeItem["DisplayOrder"] = 121; $newThemeItem.Update(); } #endregion #region Set the theme $theme=[Microsoft.SharePoint.Utilities.SPTheme]::Open($themeName, $colorfile); Write-Host $theme.Name "to" $Web.Title; $theme.ApplyTo($Web, $false); #endregion #region Set applied theme as current theme $SPQuery = New-Object Microsoft.SharePoint.SPQuery; $SPQuery.Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>"; $SPQuery.RowLimit = 1; $SPQuery.ViewFields = "<FieldRef Name='DisplayOrder'/>"; $SPQuery.ViewFieldsOnly = $true; $spListItems = $spList.GetItems($SPQuery); if($spListItems.Count -eq 1) { $spListItems[0].Delete(); } $currentThemeItem = $spList.AddItem(); $currentThemeItem["Name"] = [Microsoft.SharePoint.SPResource]::GetString([System.Threading.Thread]::CurrentThread.CurrentUICulture, [Microsoft.SharePoint.Strings]::DesignGalleryCurrentItemName); $currentThemeItem["Title"] = [Microsoft.SharePoint.SPResource]::GetString([System.Threading.Thread]::CurrentThread.CurrentUICulture,[Microsoft.SharePoint.Strings]::DesignGalleryCurrentItemName); $currentThemeItem["MasterPageUrl"] = "$relativeUrl$MasterPagePartUrl$masterpage";#$Web.MasterUrl; $currentThemeItem["ThemeUrl"] = "$ColorFilePartUrl$colorfile"; $currentThemeItem["FontSchemeUrl"] = "$FontFilePartUrl$fontfile"; $currentThemeItem["DisplayOrder"] = 0; $currentThemeItem.Update(); #endregion $Web.allowunsafeupdates = $false; Write-Host "Set" $theme.Name "theme to :" $Web.Title "(" $Web.Url ")" ; } }
<
SiteCollections
>
site
url
>http://local/sites/MyBlog<;/
theme
>Collaboration</
filesToUpload
>false</
colorFilePath
>C:\theme\collaborationcolor.spcolor</
fontFilePath
>C:\theme\collaborationfontscheme.spfont</
colorfile
>collaborationcolor.spcolor</
fontfile
>collaborationfontscheme.spfont</
masterpage
>seattle.master</
</
>http://local<;/
>true</
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue;
[xml]$inputfile = Get-Content C:\Data\theme\ThemeScriptInput.xml
foreach( $site in $inputfile.SiteCollections.site)
$colorfile=$site.AllWebs[0].GetFile("$siteurl$ColorFilePartUrl$colorfile");
$fontfile=$site.AllWebs[0].GetFile("$siteurl$FontFilePartUrl$fontfile");
$spList = $Web.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::DesignCatalog);
$theme=[Microsoft.SharePoint.Utilities.SPTheme]::Open($themeName, $colorfile);
Write-Host $theme.Name "to" $Web.Title;
$theme.ApplyTo($Web, $false);