SharePoint 2007 – Branding Your application.master Page

Most SharePoint administrators and developers are aware of the techniques for customizing the master page for a SharePoint site, so I am not going to go into detail on this topic.  However, I do want to share with you any easy technique I found for customizing the administrative pages on a SharePoint using the application.master file.

A quick background on administrative pages vs. regular SharePoint pages:  Most content pages that you create within a SharePoint site are stored within the content database and are easily styled using a custom master page and style sheet specified on the site settings page.  These pages typically consist of web part pages, home pages, and other pages you create to display SharePoint content, these pages inherit the master page and CSS settings that you specify in the site settings of your SharePoint site.

The other types of pages that you see within SharePoint pages are called “administrative pages” or “application pages”.  Those pages are supplied by Microsoft as part of the SharePoint installation and are used to configure and administer your SharePoint site, these pages are NOT stored in the content database and are instead stored on the file system in the _Layouts directory (typically this is C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\Layouts ).   Another important difference between these two types of pages is that all the styling of administrative pages is specified in a single master page named “application.master” which is stored on the file system in the _Layouts folder. 

One very important note about the styling of administrative pages using the application.master is that each SharePoint farm can only have one application.master file in the _Layouts folder, which typically means that ALL your administrative pages across your entire SharePoint farm must share the same styling.  This can present a design challenge if you are a SharePoint administrator and you are asked to have different styling for different sites and site collections within the same SharePoint farm AND you need the administrative pages to be styled consistently with those sites and site collections.  In a future post I will present some options on how to address this limitation.

Back to the easy technique for branding (styling) your application.master page.  Standard master pages and the application.master file are generally the same but do have some very slight differences.  You cannot simply copy your regular master page content into the application.master file and expect everything in SharePoint to work perfectly, they are not 100% compatible.  However, you can take your regular master page and tweak it (with little effort) to use as your application.master file.  Below is an outline of the “tweaks” that need to be made

Tweak 1.  Application.master files should not contain the delegate control for the SmallSearchInputBox.  You can simply remove the following reference from your master page:

                        <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox"/>

Tweak 2.  Application.master should also contain the following content placeholder tags, several pages within the _Layouts folder rely on these tags:

                        <asp:ContentPlaceHolder id="PlaceHolderPageDescriptionRowAttr" runat="server" />
                        <asp:ContentPlaceHolder id="PlaceHolderPageDescriptionRowAttr2" runat="server" />

Thus far I’ve only found these two tweaks, or changes, needs to be made to a master page in order to use it as your application.master page.  If you find that there are other required tweaks, please pass those along to me so that I can update my post.

SharePoint 2007 – Branding Your application.master Page

Most SharePoint administrators and developers are aware of the techniques for customizing the master page for a SharePoint site, so I am not going to go into detail on this topic.  However, I do want to share with you any easy technique I found for customizing the administrative pages on a SharePoint using the application.master file.

A quick background on administrative pages vs. regular SharePoint pages:  Most content pages that you create within a SharePoint site are stored within the content database and are easily styled using a custom master page and style sheet specified on the site settings page.  These pages typically consist of web part pages, home pages, and other pages you create to display SharePoint content, these pages inherit the master page and CSS settings that you specify in the site settings of your SharePoint site.

The other types of pages that you see within SharePoint pages are called “administrative pages” or “application pages”.  Those pages are supplied by Microsoft as part of the SharePoint installation and are used to configure and administer your SharePoint site, these pages are NOT stored in the content database and are instead stored on the file system in the _Layouts directory (typically this is C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\Layouts ).   Another important difference between these two types of pages is that all the styling of administrative pages is specified in a single master page named “application.master” which is stored on the file system in the _Layouts folder. 

One very important note about the styling of administrative pages using the application.master is that each SharePoint farm can only have one application.master file in the _Layouts folder, which typically means that ALL your administrative pages across your entire SharePoint farm must share the same styling.  This can present a design challenge if you are a SharePoint administrator and you are asked to have different styling for different sites and site collections within the same SharePoint farm AND you need the administrative pages to be styled consistently with those sites and site collections.  In a future post I will present some options on how to address this limitation.

Back to the easy technique for branding (styling) your application.master page.  Standard master pages and the application.master file are generally the same but do have some very slight differences.  You cannot simply copy your regular master page content into the application.master file and expect everything in SharePoint to work perfectly, they are not 100% compatible.  However, you can take your regular master page and tweak it (with little effort) to use as your application.master file.  Below is an outline of the “tweaks” that need to be made

Tweak 1.  Application.master files should not contain the delegate control for the SmallSearchInputBox.  You can simply remove the following reference from your master page:

                        <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox"/>

Thus far I’ve only found that this one “tweak” or change needs to be made to a master page in order to use it as your application.master page.  If you find that there are other required tweaks, please pass those along to me so that I can update my post.

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.

SharePoint 2007 – "Back" Link After Deleting a Site

After deleting a site in WSS 3.0 or MOSS 2007 the following page is displayed by default.  The “webdeleted.aspx” is a default application page provided by Microsoft, but it is easily customized.  In this article I will show you how to enhance this page to be more user friendly.

delete

The problem with this page is that the user is left hanging, with no links back to the parent site or site collection where the site was deleted from.  Below is a quick solution for adding a link labeled “Go back to parent site” to the top of this page.  When the steps are complete your users will see the following:

delete2

Steps for adding the “Go back to parent site” link.

  1. In notepad, open the file named “webdeleted.aspx” in the 12 hive, layouts folder (usually this is located at the following location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS )
  2. Located the content placeholder tag: <asp:Content ContentPlaceHolderId=”PlaceHolderTitleBreadcrumb” runat=”server”>
  3. Add the following code inside the content placeholder:  <a href=”<%SPHttpUtility.HtmlEncode(SPControl.GetContextSite(Context).Url, Response.Output);%>”>Go back to parent site</a>
  4. Save the “webdeleted.aspx” file.

When you are finished the code should look like the following:

<asp:Content ContentPlaceHolderId=”PlaceHolderTitleBreadcrumb” runat=”server”>
     <a href=”<%SPHttpUtility.HtmlEncode(SPControl.GetContextSite(Context).Url, Response.Output);%>”>Go back to parent site</a>
</asp:Content>