How To Use Visual Studio To Create Costum Master Page 1

SharePoint 2013 Hosting – HostForLIFE.eu :: How To Use Visual Studio To Create Costum Master Page

In this post we will tell you how to use Visual Studio 2013 to create custom master page in SharePoint 2013. Here, I’m using Visual Studio 2013 and SharePoint 2013 on premise for this demo. Before doing anything, go to your site settings page and then click on “Master pages and page layouts” which is under “Web Designer Galleries”. From the master page gallery, download seattle.master page as save it in your local drive. In this example, I’m using seattle.master as the base.

Step 1

Now, Open Visual Studio 2013, then File -> New -> Project. Then in the New Project dialog box, From the templates select Visual C# -> Office/SharePoint -> SharePoint Solutions. Then from the right side select SharePoint 2013 – Empty Project. Give a name and click on OK as shown in below:

How To Use Visual Studio To Create Costum Master Page 1

Step 2

Then give your local site for deployment and then choose “Deploy as a farm solution” as shown in the fig below:

How To Use Visual Studio To Create Costum Master Page 2

Step 3

Then right click on the project, then add new item. Then in the Add New Item dialog box, select Module as shown in the fig. Give a name and click on OK as shown in below:

How To Use Visual Studio To Create Costum Master Page 3

Step 4

Then delete the sample.txt from the Module folder and then past the master page which we have downloaded from the site and saved in the local drive. In my case I have given the name as “MyCustomMaster.master”. Now change the Elements.xml like below:

Step 5

Then give a meaningful name to the feature, in my case I have given the name as “ActivateCustomMasterPage”. Then open the feature and give a title and select the scope as Site as shown in below:

How To Use Visual Studio To Create Costum Master Page 4

Step 6

We will add an event receiver which will set our master page when feature got activated and will set to seattle master page when feature get deactivated. Right click on Feature then click on “Add Event Receiver” as shown in below:

How To Use Visual Studio To Create Costum Master Page 5

Step 7

Here we need to write the code ActivateCustomMasterPageEventReceiver. Write below code in the FeatureActivated event:

Step 8

Write the below code in the FeatureDeactivating event:

Step 9

Right click on the solution explorer and then Build solution. If build succeeded then Right click and then Deploy solution. Once the solution got deployed successfully in the site collection, you can go the site collection features to see our feature must be activated. Go to site settings page, then click on “Site collection features” which is under “Site Collection Administration”. In the Site Collection Features page, you will be able to see “Activate Custom Master Page” feature status is Active like below:

How To Use Visual Studio To Create Costum Master Page 6

Step 10

Now to verify if the custom master page is deployed to the site, go to the site settings page then click on “Master pages and page layouts” which is under “Web Designer Galleries”. Here you will be able to see master page under “Master Page Gallery” like below:

How To Use Visual Studio To Create Costum Master Page 7

Now we can go to the settings and see if our custom master page is selected or not. Go to the site settings page, then click on Master page under Look and Feel. To see this link make sure you have publishing feature activated in the site collection. You can also check out: Enable and Disable SharePoint 2013 publishing feature using PowerShell. Here once you click on Master Page, then in the Site Master Page Settings you will be able to see our custom master page is set in the “Site Master Page” as well as “System Master Page” as shown in below:

 

How To Use Visual Studio To Create Costum Master Page 8

Step 11

Now to check whether our feature deactivating is working fine or now. Go to the site collection feature page and deactivate the “Activate Custom Master Page” feature. Once it is successfully deactivated, go to the Master Page link under Look and Feel and you will be able to see the Seattle master page is set in the Site master page as well as settings master page.

How To Use Visual Studio To Create Costum Master Page 9

Over all if you will see your solution explorer, it will look like below:

How To Use Visual Studio To Create Costum Master Page 10

Hope this will be helpful.

SharePoint 2013 Hosting Recommendation

HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/month, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint plans as well as dedicated SharePoint options

hostforlife banner