Wednesday, September 15, 2010

Custom Master Page in Sharepoint Deploy with Feature

Hello Friends,

Let us talk about today how to apply custom master page via Feature Files.

Here is an example of Element.xml and Feature.xml Files by which we can apply custom master page to Sharepoint Site through feature.

Explanation Of Feature.xml and Elements.xml: 
--> The Feature element contains an ElementManifests element.ElementManifest references a    file named elements.xml that contains the CAML to define elements for a new .master page file. There is also a Module element used to copy TeamCustom.master  into the Sharepoint site under _catalogs/masterpages.The ElementManifest element is an essential part of the Feature definition because it references elements.xml.


<?xml version="1.0" encoding="utf-8" ?>
<Module Name="AddMasters" List="116" Url="_catalogs/MasterPage">
<File Url="TeamCustom.Master" Path="MasterPage/TeamCustom.Master"     Type="GhostableInLibrary" IgnoreIfAlreadyExists="True">
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" />

 <?xml version="1.0" encoding="utf-8"?>
<Feature Id="54F2CEA7-29D9-43e7-AB48-E4347E981E6A"  Title="GaDOE.LookAndFeel"
Description="MasterPages and Page Layouts" Version=""  Hidden="FALSE"
Scope="Site" DefaultResourceFile="core" />
       <ElementManifest Location="elements.xml"/>
       <ElementFile Location="MasterPage/TeamCustom.Master"/>

Enjoy Sharepoint Branding with the master pages!!!
Disha Shah


  1. Hi,
    I had apply the feature to use my main site collection and used it for all the sub-sites. when i uninstalled the feature. it should remove the file from the masterpage gallery. But in fact the master page is still there in master page gallery. Infact i am unable to delete the master page.

    Do you know any work around to remove the custom.master masterpage once you uninstall the feature.

    Thanks in Advance.

    Aniekt Patel

  2. Hi Aniket
    After install your feature for master page, generally we upload that master page to particular site MasterPage gallery.

    So when we uninstall feature it will delete that files from 12\Template\Feature but not from the MasterPage Gallary.

    To delete from masterpage gallery you need to write FeatureeventReceiver and delete that masterpage file.

    But easy way is go to masterpage gallery and delete it.

    If you go to master page gallery and tried to delete that it gives error “Reference found “, “Some pages using these master page” etc.

    But there is a workaround for this. Create another folder in the masterpage folder and then drag the master page you want to delete into it. Then delete the folder and your master page is gone.

    Hope this helps!!!
    Disha Shah