Book Image

SharePoint 2013 WCM Advanced Cookbook

By : JOHN CHAPMAN
Book Image

SharePoint 2013 WCM Advanced Cookbook

By: JOHN CHAPMAN

Overview of this book

Table of Contents (19 chapters)
SharePoint 2013 WCM Advanced Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Navigate to the site in your preferred web browser.

  2. Select Site settings from the Settings menu.

  3. Select Themes from the Web Designer Galleries section.

  4. Select the folder named 15.

  5. Select New Document to upload and save the color palette file.

    Note

    Alternatively, SharePoint 2013 also supports dragging-and-dropping files from Windows Explorer to the web interface in most browsers.

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.

Uploading a custom color palette using SharePoint Designer

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:

  1. Open the site in SharePoint Designer.

  2. In the Site Objects pane on the left-hand side, select All Files.

  3. In the All Files list, navigate to _catalogs | theme | 15.

  4. In the ribbon, click on Import Files.

  5. Select Add File to browse and select the color palette file.

  6. Click on OK to import the color palette file.

Uploading a custom color palette using PowerShell

Follow these steps required to upload a custom color palette using PowerShell:

  1. Get the site using the Get-SPWeb Cmdlet:

    $web = Get-SPWeb http://sharepoint/site
    
  2. Assign the path of the color palette file to a variable:

    $filePath = "C:\mypalette.spcolor"
    
  3. Get the /_catalogs/theme/15 folder from the SPWeb object:

    $themeFolder = $web.Folders["_catalogs"].Subfolders["theme"].Subfolders["15"]
    
  4. Get the filename from the file path using the GetFileName method of the System.IO.Path class:

    $fileName = [System.IO.Path]::GetFileName($filePath)
    
  5. Get the contents of the file using the OpenRead method of the System.IO.File class:

    $fileStream = [System.IO.File]::OpenRead($filePath)
    
  6. 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 to true to specify that this should override an existing file if it already exists by the same name:

    $themeFolder.Files.Add($fileName, $fileStream, $true)
    
  7. Call the Update method on the folder to update the Files collection:

    $themeFolder.Update()
    
  8. Use the Dispose method to discard the SPWeb object:

    $web.Dispose()
    

Uploading a custom color palette with code using the server-side object model

Follow these steps to upload a custom color palette with code using the server-side object model:

  1. Open the site collection containing the site in a using statement:

    using (var site = new SPSite("http://sharepoint/site"))
  2. Open the site in a using statement:

    using (var web = site.OpenWeb())
  3. Assign the path of the color palette file to a variable:

    var filePath = "C:\mypalette.spcolor";
  4. Get the /_catalogs/theme/15 folder from the SPWeb object:

    var themeFolder = web.Folders["_catalogs"].SubFolders["theme"].SubFolders["15"];
  5. Get the filename using the GetFileName method of the System.IO.Path class:

    var fileName = Path.GetFileName(filePath);
  6. Get the contents of the file using the OpenRead method of the System.IO.File class:

    var fileStream = File.OpenRead(filePath);
  7. 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 to true to specify that this should override an existing file if it already exists by the same name:

    themeFolder.Files.Add(fileName, fileStream, true);
  8. Call the Update method on the folder to update the Files collection:

    themeFolder.Update();

See also