Monday, April 02, 2007

Creating a Custom Master Page & Deploying it as a Feature

First of all thanks to Heather Soloman who posted a great article about this Create a Feature: Master Pages for Site Collections.

Here's how i set up the Custom Masterpages and depoyed them as a feature:

Create the Feature

  1. Create a folder called CustomMasterPages under the Features directory on the web server.
  2. Inside the CustomMasterPages folder create the folders:
    • en-us
    • Images
    • Styles
    • MasterPages
    • PageLayouts
    • JavaScript
  3. Copy these two files from the Features directory PublishingLayouts:
    • Feature.xml, and
    • ProvisionedFiles.xml
  4. Create a file in the MasterPages folder called CustomMaster.master
  5. Open CustomMaster.master in notepad and paste the following minimal master page code from Microsoft.
  6. Alternatively Heather Soloman has created another version of the minimal master page which is the version I used in the end. The reason for this is that Heather's version is a stripped out version of the default.master master page which includes all the functionality available. The Microsoft version has only the minimal elements included.
  7. Format the master page with XHTML tags & CSS.
  8. Change the doc type to XHTML transitional.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">

  9. Edit the ProvisionedFiles.xml file to provision the master page, CSS files & images etc.


    <!-- _lcid="1033" _version="12.0.4407" _dal="1" -->
    <!-- _LocalBinding -->
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">

    <Module Name="OSGMasterPages" Url="_catalogs/masterpage" Path="MasterPages" RootWebOnly="TRUE">
    <File Url="tr_portalMaster.master" Type="GhostableInLibrary">
    <Property Name="ContentType" Value="Teleport Master Page - DEFAULT PORTAL LAYOUT" />
    <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/tr_teleportLogo100.gif, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/tr_teleportLogo100.gif" />
    <Property Name="MasterPageDescription" Value="This is the TelePort master page (DEFAULT CSS LAYOUT) for use with collaboration or publishing sites." />
    </File>
    </Module>
    <Module Name="PublishingLayoutsPreviewImages" Url="_catalogs/masterpage" IncludeFolders="??-??" Path="" RootWebOnly="TRUE">
    <File Url="tr_teleportLogo100.gif" Name="Preview Images/tr_teleportLogo100.gif" Type="GhostableInLibrary">
    </File>
    </Module>
    <Module Name="Images" Url="Style Library/Images" Path="Images" RootWebOnly="TRUE">
    <File Url="tr_telerealLogo102.gif" Name="tr_telerealLogo102.gif" Type="GhostableInLibrary" />
    </Module>
    <Module Name="OSGStyles" Url="Style Library" Path="Styles" RootWebOnly="TRUE">
    <File Url="tr_core.css" Type="GhostableInLibrary" />
    <File Url="tr_portalMaster.css" Type="GhostableInLibrary" />
    <File Url="tr_portalMaster_IE6.css" Type="GhostableInLibrary" />
    <File Url="tr_portalMaster_IE55.css" Type="GhostableInLibrary" />
    </Module>
    </Elements>

  10. Add a preview image to the language folder (en-us).
  11. Create a unique GUID
  12. In the Feature.xml file:
    • Change the feature ID to the unique GUID
    • Change the title to Custom Master Pages
    • Change the Hidden state to False
  13. Recycle the app pool on the WFE website

Deploying the Feature

  1. On the web server (DEV02) launch command prompt and change dir to:

    cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN

  2. Install the feature using STSADM:

    stsadm -o installfeature -name CustomMasterPages

  3. Go to Site Collection Features on the portal top level site and activate the feature.

    To use the master page select from the drop down list on Site Settings / Site Master Page Settings

Redeploying a Feature

Changes made to the feature require that the feature is redeployed. For example; adding new master pages, css files etc. To do this:

  1. On the web server (DEV02) launch command prompt and change dir to:

    cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN

  2. Reinstall the feature using STSADM:

    stsadm -o installfeature -name CustomMasterPages -force

  3. Reactivate the feature in Site Collection Features by deavctivating and the activating it.

2 comments:

  1. hi,
    i find this site, when i was looking for example of deploying custom master page from visual studio. so here is a blogpost, which describe that in detailed way, if any other visitor have the same issue:

    http://sharepoint-darius.blogspot.com – Sharepoint Custom Master Page

    ReplyDelete
  2. I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

    ReplyDelete