SharePoint 2007 – Branding Your Site Application Pages

If you’ve ever tried to customize the branding of a MOSS 2007 or WSS 3.0 site you’ve probably discovered that SharePoint application pages (pages that physically reside in the /_layouts folder on the file system) share a common master page and thus share the same style sheets.  Said another way; unlike SharePoint site collections and sites (where you can change the branding of sites by specifying different master pages and style sheets per site) your application pages all use the same master page (application.master) across all site collections and sites on a web application.

Examples of application pages include the following: groups.aspx, editview.asp, pagesettings.aspx, people.aspx, viewlsts.aspx … and many more, about 426 .aspx files in all.

To customize the branding on application pages I came up with a simple technique to dynamically apply different style sheets to the application.master by adding some C# code to the application.master file.  The instructions and sample code below assume that you want to load one of two style sheets depending on the host name (in this case we look for http://mosssitename/ and load the style sheet named css1.css otherwise we load the style sheet named css2.css)

1.  Add the following code inside the <HEAD> </HEAD> tags on your application.master file.

<asp:literal id="DynamicCSSLiteral" runat="server"/>
<script runat="server">
  protected override void OnLoad(EventArgs e) {
    switch(Request.ServerVariables["HTTP_HOST"].ToString())
    {
        case "mosssitename":
            this.DynamicCSSLiteral.Text = "<link rel=stylesheet type=text/css href=/_layouts/1033/styles/css1.css />";
            break;
        case "localhost":
            this.DynamicCSSLiteral.Text = "<link rel=stylesheet type=text/css href=/_layouts/1033/styles/css2.css />";
            break;
        default:
            break;
    }
  }
</script> 

2.  Modify the top line of your application.master file so that the @Master reference has the value AutoEventWireup=”true”.

<%@ Master AutoEventWireup="true" language="C#" %>

Feel free to reply to this post if you find any other solutions to branding application pages in SharePoint 2007.

Advertisement

One Response

  1. Thank you very much. I was looking for some code on how to change stylesheets for specific clients, and your code combined with javascript saved the day:).

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.