SharePoint 2010 provides a user friendly approach to applying custom fonts and colors to sites.

There is a way to read the theme information from your code and make your solution blend with its host site.


The theme information for the sites is stored in a special type of files – thmx files.

Following is an article on how to create custom theme files and deploy them to SharePoint 2010: Working with SharePoint 2010 Themes (Anweshi Deverasetty)

Here is an image, which works a map between the colors of the Thmx Theme and the site: THMX theme reference

SharePoint’s API provides a very useful class for handling the theme information: ThmxTheme Class – it is important to mention that this class and its functionality are accessible in sandboxed solutions.

Working with Themes

The following code snippet gets the URL of the thmx theme file, which is currently applied to the site:

// NOTE: The url parameter ThemeOverride is used when the user goes to the Site Theme settings
// and clicks on the Preview button for the selected theme.
string themeOverride = Page.Request.QueryString["ThemeOverride"];
string themeUrl = string.IsNullOrEmpty(themeOverride)
    // Use the theme for the site.
    ? ThmxTheme.GetThemeUrlForWeb(SPContext.Current.Web)
    // Use the Preview theme.
    : themeOverride;

// NOTE: If the site uses the default SharePoint theme, the themeUrl will be empty.
if (!string.IsNullOrEmpty(themeUrl))
    ThmxTheme theme = ThmxTheme.Open(SPContext.Current.Site, themeUrl);
    // Handle the fonts and the colors in the theme
    // and pass them to your solution.

The drawback of this approach is that if the site uses the default SharePoint theme, themeUrl will be empty.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *