Steps To Create Custom Master Page In SharePoint 2013 Using Visual Studio

Introduction

SharePoint master pages gives the common page layout and interface for SharePoint pages. Master pages provide the same look and feel for all the pages in our site. It lets you create and update header, navigation links, Site Actions menu elements in one place, rather than changing them on each Web pages. In this article I will explain, how to create custom Master Page in SharePoint 2013 using Visual Studio.

Pre-Requisites

  1. Open Visual Studio.

  2. Open New Project dialog box. Expand Office/SharePoint node and then choose SharePoint Solutions.

    SharePoint

  3. Choose SharePoint 2013 – Empty Project template. Name the project as CustomSharePointProject.

    SharePoint

  4. Choose the Deploy as a farm solution radio option button and choose Finish button.

    SharePoint

  5. “CustomSharePointProject” SharePoint project creates.

    SharePoint

Create Master Page

  1. Right click on CustomSharePointProject -> Add -> New Item.

    SharePoint

  2. Add Module from the Add New Item window. Name it as “MasterPages”.

    SharePoint

  3. Module “MasterPages” creates the folder structure, as given below-

    SharePoint

  4. Rename the Sample.txt file as MyMasterPage.master.

    SharePoint

  5. Open the existing SharePoint site in SharePoint Designer 2013.

  6. Go to All Files -> _catalog -> masterpages.

    SharePoint

  7. Open the v4.master file. Copy this file content and place in our MyMasterPage.master file.

    SharePoint

  8. Do modification as per our requirement in the MyMasterPage.master.

    <?xml version="1.0" encoding="utf-8"? /> <elements xmlns= ">

  9. Open Element.xml file. Put the code, given below in Elements.xml file. Modify according to your folder structure.
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
    3.     <Module Name="MasterPages" List="116" Url="_catalogs/masterpage" RootWebOnly="TRUE">  
    4.         <File Path="MasterPages\MyMasterPage.master" Url="MasterPages/MyMasterPage.master" Type="GhostableInLibrary" ReplaceContent="TRUE" Level="Published" /> </Module>  
    5. </Elements>  
    <?xml version="1.0" encoding="utf-8"? /> <elements xmlns= ">

  10. List="116" Url="_catalogs/masterpage" RootWebOnly="TRUE" attributes needs to be added in <Module> tag.

  11. Type="GhostableInLibrary" ReplaceContent="TRUE" Level="Published" attributes need to be added in <File> tag.

  12. Build and deploy SharePoint solution.

  13. Go to SharePoint site, Site Actions -> Site Settings -> Web Designer Galleries -> Master pages and page layouts.

    <?xml version="1.0" encoding="utf-8"? /> <elements xmlns= ">

  14. Our module “MasterPages” folder creates.

    <?xml version="1.0" encoding="utf-8"? /> <elements xmlns= ">

  15. Open MasterPages folder. Our custom MyMasterPage.master creates. If it is not published, please check-in and publish the master file as a major version.

    MasterPages

  16. Make sure that “SharePoint Server Publishing Infrastructure” is activated under “Site Collection Features” and “SharePoint Server Publishing” is activated under “Manage Site Features”.

  17. Go to SharePoint site, Site Actions -> Site Settings -> Look and feel -> Master Page.

    MasterPages
  18. Select our “MyMasterPage” master page from the drop down and click OK button. It will apply the master page to our SharePoint site pages.

    MasterPages

Summary - Thus, you have learned how to create a custom Master page in SharePoint 2013, using Visual Studio.