Sunday, October 13, 2013

Simple Steps to create custom master page in SharePoint

Open Visual Studio 2010/2012,  Create Empty SharePoint project. 

Right Click Add a new item to the project and choose a module item, Enter proper name to the module.

Module contains two files. 1. Elements.xml 2. Sample.txt

Rename sample.txt to custombrand.master.

Go to master page gallery, select v4.master and change the user interface of master accourding to your needs.

Replace file with custombrand.master. file in Visual Studio. 

Modify Elements.xml file and change the masterpage reference to the custombrand.master. 

<File Path .... URL="custombrand.master"...

Set the scope of feature to Site Collection level. 

Add a Event Receiver to the feature, Go the feature Activated event add the following code:


SPWeb currentWeb = properties.Feature.Parent as SPWeb;
Uri masterpageURI = new Uri(currentWeb.Url + "/_catalogs/masterpage/custombrand.master");
currentWeb.MasterUrl = masterpageURI.AbsolutePath;
currentWeb.CustomMasterUrl = masterpageURI.AbsolutePath;
currentWeb.Update();

Build and Deploy the solution 

Activate the feature to apply the changes. Browse any site and check the branding applied to the site.

No comments:

Post a Comment