Today’s post cover the information how to deploy a custom master page in SharePoint 2010. Here we go

1. Create an empty SharePoint project. This can have any name you like.
2. Add an new item to the project and choose a module.
3. You can rename the module if you want to, I will leave the name at Module1.
4. After the module is created it contains an elements.xml file and a sample.txt file. The sample.txt file can be renamed to sample.master.


This is a simple example SharePoint 2010 master page content.

1. Open up SharePoint Designer and open the site you are working on
2. Choose Master Pages on the left side
3. Open v4.master
4. Copy the contents of v4.master and past them in your sample.master file in Visual Studio. Make the changes you want to.
5. Note how the elements.xml file has changed to reference the sample.master rather than the sample.txt


6. Make sure the module is added to a feature in your project that is scoped at the site (= site collection) level

You could stop here and this solution will deploy your sample.master master page to the master page gallery of your site collection.
This will not apply the master page to the site collection when the feature gets activated though. It will only make it available for selection.

7. If you the master page to be applied when the feature gets activated you right click on the Feature1 and you add an event receiver. This will add a feature receiver file to the feature.
8. In this file we will add some code that will apply the sample.master master page when the feature gets activated and it will apply the v4.master when the feature gets deactivated.


Now if you activate the feature the code in the feature receiver will run and will apply sample.master to the site. As you can see we change both the MasterUrl and the CustomMasterUrl. The MasterUrl is used on all pages that are not publishing pages. This means it is used on the pages in the sitepages library and on the pages in the _layouts directory like the settings page for instance. The CustomMasterUrl is only used on pages that are stored in the Pages library. This library is created when the SharePoint Server Publishing Infrastructure features is activated on the site collection and the SharePoint Server Publishing feature is activated on the site.

You can also use the SharePoint user interface to apply a new master page. The Site Master Page is the equivalent of the CustomMasterUrl and the System Master Page is what the object model calls the MasterUrl.