Creating a custom Master page in SharePoint 2010 using Visual Studio 2010


In this article we will be seeing how to create a custom master page in SharePoint 2010 using Visual Studio 2010.

Steps Involved:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Empty SharePoint Project from the installed template SharePoint 2010.

    1.gif
     
  • Enter the Name.
  • Click Ok.
  • Enter the local site that you want to use it for debugging.
  • Select "Deploy as a sandbox solution".
  • Click Finish.
  • Right click on the solution and click on "Add a new item".
  • Select the Module template from the installed templates.

    2.gif
     
  • Enter the name and click ok.
  • Rename the Sample.txt to Sample.master.
  • Replace the code with the following code snippet.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Module Name="Module" List="116" Url="_catalogs/masterpage">
        <File Path="Module\Sample.master" Url="Module/Sample.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="false" />
      </Module>
    </
    Elements>
     
  • Go to the SharePoint Designer.
  • Open some existing site in the SharePoint Designer 2010.
  • Go to Navigation => Site Objects =>Master Pages.
  • Make a copy of v4.master.
  • Do some modifications in the copy of v4.master and copy the code.
  • Paste the code in the Sample.master.

Publish the master page:

  • Go to Site Actions => Site Settings =>Galleries => Master pages and page layouts => Module =>Sample.master.
  • Go to the ECB menu, click on "Check in".

    3.gif
     
  • Go to the ECB menu, click on "Publish a major version".

    4.gif
     
  • Go to the ECB menu, click on "Approve/Reject".

    5.gif
     
  • Select the "Approved" option. Click on Ok.

    6.gif

Change the master page of the SharePoint site with the custom master page

  • Go to the SharePoint Site => Site Actions => Site Settings => Site Collection Administration => Site Collection Features.
  • Activate the following feature "SharePoint Server Publishing Infrastructure".

    7.gif

     
  • Go to Site Actions => Site Settings =>Site Actions => Manage Site Features.
  • Activate the following feature "SharePoint Server Publishing".

    8.gif
     
  • Go to Site Actions => Site Settings => Look and feel => Master Page.
  • Select the custom master page as shown in the following.

    9.gif
  • Click Ok. 

erver'>
Up Next
    Ebook Download
    View all
    Learn
    View all