Uploading a custom color palette
SharePoint 2013 comes with 32 color palettes. If you are incorporating the branding of an organization you will likely need to customize the colors to match. Color palettes are simple XML files; however, they contain over 90 configured values. Identifying the appropriate values to update manually can be tedious. To simplify the process of creating new color palettes, Microsoft has made available the SharePoint Color Palette Tool for download. This tool can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?id=38182.
The SharePoint Color Palette Tool provides:
- A live preview using the same layout as the live preview when configuring and applying a composed look, which we covered previously
- The configuration of each color element
- The configuration of which colors to use, when displaying in the color palette's drop-down list in the web interface
- The option to preview with a background image
- A preview utilizing various layouts in order to ensure the color palette applies well to the various page layouts and provides proper contrast between elements
We won't go into all of the details of using the tool to create color palettes. We will, however, cover how to upload the color palettes once created by the SharePoint Color Palette Tool.
Getting ready
To complete this recipe you will need a custom color palette created and ready to upload.
How to do it...
Follow these steps to upload a custom color palette:
- Navigate to the site in your preferred web browser.
- Select Site settings from the Settings menu.
- Select Themes from the Web Designer Galleries section.
- Select the folder named
15
. - Select New Document to upload and save the color palette file.
How it works...
The SharePoint color palettes are simply stored as files in a folder in a document library found at /_catalogs/theme/15
. In this recipe, we uploaded our custom color palette to this document library and made it available for use when applying composed looks. The following screenshot shows our custom color palette in the folder named 15
which is inside the Theme Gallery library:
There's more...
A color palette may also be uploaded with SharePoint Designer 2013, PowerShell, or code using the server-side object model.
SharePoint Designer 2013 can be used to browse and manage document libraries in SharePoint 2013. Follow these steps to upload a custom color palette using SharePoint Designer 2013:
- Open the site in SharePoint Designer.
- In the Site Objects pane on the left-hand side, select All Files.
- In the All Files list, navigate to _catalogs | theme | 15.
- In the ribbon, click on Import Files.
- Select Add File to browse and select the color palette file.
- Click on OK to import the color palette file.
Follow these steps required to upload a custom color palette using PowerShell:
- Get the site using the
Get-SPWeb
Cmdlet:$web = Get-SPWeb http://sharepoint/site
- Assign the path of the color palette file to a variable:
$filePath = "C:\mypalette.spcolor"
- Get the
/_catalogs/theme/15
folder from theSPWeb
object:$themeFolder = $web.Folders["_catalogs"].Subfolders["theme"].Subfolders["15"]
- Get the filename from the file path using the
GetFileName
method of theSystem.IO.Path
class:$fileName = [System.IO.Path]::GetFileName($filePath)
- Get the contents of the file using the
OpenRead
method of theSystem.IO.File
class:$fileStream = [System.IO.File]::OpenRead($filePath)
- Add the file to the
Files
collection of the folder using the name of the file and file contents. We are setting the third parameter totrue
to specify that this should override an existing file if it already exists by the same name:$themeFolder.Files.Add($fileName, $fileStream, $true)
- Call the
Update
method on the folder to update theFiles
collection:$themeFolder.Update()
- Use the
Dispose
method to discard theSPWeb
object:$web.Dispose()
Follow these steps to upload a custom color palette with code using the server-side object model:
- Open the site collection containing the site in a
using
statement:using (var site = new SPSite("http://sharepoint/site"))
- Open the site in a
using
statement:using (var web = site.OpenWeb())
- Assign the path of the color palette file to a variable:
var filePath = "C:\mypalette.spcolor";
- Get the
/_catalogs/theme/15
folder from theSPWeb
object:var themeFolder = web.Folders["_catalogs"].SubFolders["theme"].SubFolders["15"];
- Get the filename using the
GetFileName
method of theSystem.IO.Path
class:var fileName = Path.GetFileName(filePath);
- Get the contents of the file using the
OpenRead
method of theSystem.IO.File
class:var fileStream = File.OpenRead(filePath);
- Add the file to the
Files
collection of the folder using the name of the file and file contents. We are setting the third parameter totrue
to specify that this should override an existing file if it already exists by the same name:themeFolder.Files.Add(fileName, fileStream, true);
- Call the
Update
method on the folder to update theFiles
collection:themeFolder.Update();
See also
- The Color palettes and fonts in SharePoint 2013 article on MSDN at http://msdn.microsoft.com/en-us/library/jj945889.aspx
- The How to: Upload a file to a SharePoint Site from a Local Folder article on MSDN at http://msdn.microsoft.com/en-us/library/ms454491(v=office.14).aspx
- The SPWeb class topic on MSDN at http://msdn.microsoft.com/en-us/library/Microsoft.SharePoint.SPWeb.aspx
- The SPSite class topic on MSDN at http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.aspx
- The Get-SPWeb topic on TechNet at http://technet.microsoft.com/en-us/library/ff607807.aspx