Sunday, 6 April 2014

Create Custom Master Page in SharePoint Designer 2010 step by step


Create Custom  Master Page in SharePoint Designer 2010  step by step

1 Create Web Application


Create a web application where we will make some modifications. Choose any name for it, and be sure that it works correctly. I created mine in my test environment http://master.Spdev.local:888

You don’t have to fill this page with any data or document since we will only change the style of this page.

2012-03-12-CreateCustomCSS-01.png

2 SharePoint Designer


SharePoint Designer is used for the management of SharePoint sites and lists, for creating and managing internal and external data sources, creating views and forms to work with data, creating workflows in order to represent business processes and finally SharePoint Designer is used for branding sites by customizing the look feel.

SharePoint Designer 2010 can be downloaded for free from Microsoft while SharePoint Designer 2007 wasn’t free of charge at the release of SharePoint 2007 which changed during time. While SharePoint Designer 2007 offered you the ability to edit SharePoint and non-SharePoint sites this has changed with the version published in 2010: You can only edit SharePoint 2010 sites using SharePoint Designer 2010.

SharePoint Designer 2010 is available in a 32bit and a 64bit version. If you intend to use SharePoint Designer 2007 besides the 2010 version you need to install the 32bit version of SharePoint Designer 2010.

One major complaint with the 2007 version was the difficult lockdown of SharePoint Designer 2007 which has changed with SharePoint Designer 2010: You can now easily manage the capabilities at the web application or site collection level.

2.1 SharePoint Designer 2010 download


Here are the downloads including Service Pack 1:


3 Install SharePoint Designer


The first step in this process of course, is to get SharePoint Designer installed. To do so, I am starting from the first site I have created in my new environment.

2012-03-12-CreateCustomCSS-02c.png

Since I do not already have Designer 2010 installed, a dialog window pops up, basically letting me know that I do not have it installed, and I can do so. Just like SharePoint Designer 2007, SharePoint Designer 2010 will be free for all users. And since the Beta is all that is around now, that’s what it will install for me

2012-03-12-CreateCustomCSS-03.png

I select the language I want to install SharePoint Designer in (German, Spanish, Japanese, French, Russian, and Chinese are other available languages that can be selected, in addition to English, as shown above), and choose my platform. Even though SharePoint 2010 is only 64-bit, SharePoint Designer 2010 is available in both 32 and 64 bit, as it is intended to be run from the desktop, and many of us still run 32 bit desktops, as we probably will for a long time to come.

Once done, selecting the Download button goes out and fetches the right download, and prompts me to run and/or save it.

2012-03-12-CreateCustomCSS-04.png

It’s sizeable for my options as I've chosen (English 64-bit) at 277MB, so I'm happy that I have a nice and fast connection.

Once it’s up and running, the installer will extract the files, and then move on.

2012-03-12-CreateCustomCSS-05.png

You have the usual EulA; agree and continue

2012-03-12-CreateCustomCSS-06.png

Once accepted, you really cannot miss what is needed on the next screen. Microsoft made sure of that.

2012-03-12-CreateCustomCSS-07.png

However, you can customize your installation by clicking on the Customize button, setting a new installation directory, setting your user information, and adding or removing features from the install. With the default installation, it’s a fairly hefty installation at 1.03G, but, I have a feeling it will be well worth it…

2012-03-12-CreateCustomCSS-08.png

The installation begins (of course after you have clicked the Install Now button). And that’s it. You’re done!

2012-03-12-CreateCustomCSS-09.png

4 Basic Designs


4.1 Active features


Where do you set the master page / page layouts if you create a Team Site / non publishing site collection? Well, Microsoft obviously knew that people would want to use the publishing features with the non-publishing enabled site collections, so this is an example of where the feature framework really works well. To resolve the “problem” simply complete the following steps:

  • Navigate to the landing page of your newly created site collection
  • Click on “Site Actions”
  • Click on “Site Collection Features”
  • Enable “SharePoint Server Publishing Infrastructure”

2012-03-12-CreateCustomCSS-10.png

Enable on site collection level

2012-03-12-CreateCustomCSS-11.png

  • Click on “Site Actions”
  • Click on “Manage site features”
  • Enable “SharePoint Server Publishing”

Enable on a site level

Once completed, you can again access the master pages and page layouts via site settings as you would normally do for a publishing portal.

4.2 Leave Default Master Pages in Peace


SharePoint 2010 comes with three out-of-box Master Pages – v4.master (the default SP2010 design), is the default.master In this tutorial we will create a new masterpage using the v4.master as a template and then connect the newly created custom Master Page to our site. It is a good idea to leave the default Master Pages untouched (at least for the examples in this post).

First we need to clone the v4.master file. Open SharePoint Designer 2010, and from the Sites tab select the Open Site icon and enter your site URL.

2012-03-12-CreateCustomCSS-12.png

The site root will be opened in SharePoint Designer 2010. Now select Master Pages from the left menu, click on the v4.master file and press CTRL+C and CTRL+V to create a copy of the .master file.

Name your master page – click on the Rename icon in the ribbon and enter your custom name (for example myCustom.master).

2012-03-12-CreateCustomCSS-13.png

Using the newly created master page we are now ready to make the modifications. Users of your SharePoint site will not notice that we are changing anything, and if you break something – it will be the custom master page, not the one users are seeing.

4.3 Create a Custom CSS to Add Branding


Next we need a CSS file which overrides the default core4.css style definitions. To see some changes to our customizations, we will include the fixed width style for our new master page.

Open SharePoint Designer 2010, select All files from the left menu and then enter the Style library.

To create a new css file, right click on the Style Library and select New > CSS from menu.

2012-03-12-CreateCustomCSS-14.png

Name this file myCustom.css, just to keep the naming schema consistent with our custom Master Page.

Right click the newly created .css file and select the Edit file in Advanced Mode option.

2012-03-12-CreateCustomCSS-15.png

Now enter some code in the css file. One thing we will do in this tutorial is to render the SharePoint site with a fixed width of 1024 pixels (making a site fixed width is actually a very difficult task using just SharePoint 2010). Additionally, we will also change the ribbon background color and the site background color.

Enter the following code in your css file:



 

#s4-bodyContainer {

                width: 1024px !important;

                margin-left:auto;

                margin-right:auto;

}

body #s4-ribbonrow {

                background-color:#865102;

}

body.v4master {

                overflow: visible;

                background-color:black;

}

.ms-cui-ribbonTopBars {

                width: 1024px !important;

                margin-left:auto;

                margin-right:auto;

}

.ms-cui-ribbonTopBars > div {

                border-bottom:1px solid transparent !important;

}



2012-03-12-CreateCustomCSS-16.png

We now have a custom CSS in the Style Library and a custom Master Page. Now we need to associate the css file with the custom Master Page.

Open the myCustom.master file with SharePoint Designer (in advanced editing mode). You will see the site preview, because by default it will open your Master Page on the Design tab.

2012-03-12-CreateCustomCSS-17.png

Click the Code tab on the bottom of the editor. You will see the entire Master Page code and content, with many placeholders, Server Ribbon code etc. Fortunately, you don’t have to learn all of these to do some serious branding and modification.

First, we need to connect our Master Page with the css file. Within the <head> tag, we need to add a link to our custom CSS file:

<link href=”/Style%20Library/myCustom.css” rel=”stylesheet” type=”text/css” />

Now modify the s4-workspace area so it will read our css file properly:

Find the line:

<div id=”s4-workspace”>

and replace it with:

<DIV id=”s4-workspace” class=”s4-nosetwidth”>

This will add the class attribute to s4-workspace tag. Without this, our fixed size setting in the CSS file will be overridden by the default inline CSS.

Now we can test our Master Page, before we link it to our production site. The best way is to create a new test page from the selected Master Page. Go back to the Master Pages item in the left menu, and right-click our myCustom.master file, then select the New from Master Page option.

2012-03-12-CreateCustomCSS-18.png

Give the site a name such as myCustom_Site and select where it should be created – the default Site Pages is fine.

After a while a new page will be created and SharePoint Designer will open it for editing (in code view). Click the Preview icon on the ribbon to see your changes.

4.4 Going Live with Your Custom SharePoint Master Page


If we have ensured that the newly created Master Page looks fine we can now connect it with our live production SharePoint site.

Open SharePoint Designer 2010, navigate to the Master Pages option in the left menu, right click the myCustom.master file and select Set as default Master Page.

2012-03-12-CreateCustomCSS-19.png

Now, if you go to your main site (in my SP farm it’s http://master.spdev.local:888/) you should see the changed layout

2012-03-12-CreateCustomCSS-20.png


Reference

https://www.nothingbutsharepoint.com/sites/eusp/pages/create-custom-css-and-master-page-in-sharepoint-2010.aspx

 

SharePoint 2010 Deploy & set Custom Masterpage per Feature

SharePoint 2010 Deploy & set Custom Masterpage per Feature

Good Article by Karsten Pohnke

http://www.ilikesharepoint.de/2013/03/sharepoint-2010-deploy-set-custom-masterpage-per-feature/

 

Deploy SharePoint 2010 Branding as a Farm Solution

Deploy SharePoint 2010 Branding as a Farm Solution


how to package and deploy SharePoint Branding as a farm solution. I will also walk you through how to add CSS and JavaScript files to custom master page. We can develop custom master pages with the help of SharePoint development tools in Microsoft Visual Studio 2010.
If you have multiple web front end servers/ if you have a requirement to apply custom branding across entire farm / if you want to have a consistent branding across multiple site collections, farm solution is the ideal approach. For larger SharePoint implementations it is recommended that you deploy branding as a farm solution. This approach will let you store all the branding files (CSS, Images) at one centralized location on the file server within 14 hive and it deploys all of the custom branding files to the correct location on each web front end server.
The farm solution should work for both SharePoint Foundation 2010 and Microsoft SharePoint Server 2010. There is no need to enable SharePoint Server Publishing infrastructure and SharePoint Server publishing feature. FYI, Publishing features are available only in SharePoint Server 2010 (standard and enterprise), but not in SharePoint 2010 Foundation.
Note: You have to be a farm administrator in order to deploy the farm solutions.

Creating SP2010Branding Project

Let’s get started! Open Visual Studio 2010, Choose “Empty SharePoint Project” and name it as SP2010Branding as shown in Figure 1.

Figure 1: Empty SharePoint 2010 Project
When you create the new SharePoint project, the SharePoint Customization Wizard prompts you to provide a URL to a local SharePoint site and to select either Deploy as a sandboxed solution or Deploy as a farm solution. Be sure to select Deploy as a farm solution, as shown in Figure 2. (After you enter the local site URL, click on “validate” to make sure you are connected to SharePoint)

Figure 2: Deploy as a farm solution
In the Solution Explorer right click on “SP2010Branding” node, select Add and then New Item. In the dialog box, select Module Item and name it as MyCustomMasterPages as shown in Figure 3.

Figure 3: Create SharePoint Module Item
If you have a look at the solution explorer now, it will contain the items as shown in the figure below:

The SharePoint Module Item that you just added comes with two files named Elements.xml and Sample.txt. Rename Sample.txt file to CustomBranding.master. Now open Elements.xml, the module inside elements tag will read as below:
<Module Name="MyCustomMasterPages">
  <File Path="MyCustomMasterPages\CustomBranding.master" Url="MyCustomMasterPages/CustomBranding.master" />
</Module>
Since all the SharePoint master pages are stored at http://yoursharepointsite/_catalogs/masterpage, we have to add our custom master page to the same location. In order to do that, we have to replace the above module element with the following one.
<Module Name="MyCustomMasterPages" Url="_catalogs/masterpage">
  <File Path="MyCustomMasterPages\CustomBranding.master" Url="CustomBranding.master" Type="GhostableInLibrary">
    <Property Name="UIVersion" Value="4" />
    <Property Name="ContentTypeId" Value="0x010105" />
  </File>
</Module>
We are almost there with the initial set up that is required! After making the above changes your elements file should look like the following.

If you want add multiple custom master pages to the solution you can add your master page under MyCustomMasterPages node and more importantly you have to modify the Elements.xml file. For each master page that you add, you should modify the inner File Element corresponding to that particular master page like how we did above.
The next step is to replace the contents of the CustomBranding.master file. The best way to start is copy the contents from v4.master (which is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\v4.master) and paste it into our CustomBranding.master.
Currently, your custom master page is exactly similar to the standard SharePoint 2010 master page (v4.master). At this point, we will make some modification to our master page so that you see the visual difference.

Adding Image Files and CSS

Right click on SP2010Branding project node and Add then SharePoint “Images” Mapped Folder as shown in the Figure 4. Since we are adding these files to 14 hive Visual Studio will automatically add a sub folder named SP2010Branding (typically it will be your project name) to the Images folder to ensure that we are not overwriting/modifying any files that exist in 14 hive. Now go ahead and add an image called background to the SP2010Branding Subfolder (Don’t get confused with the SP2010Branding project node, add the image to SP2010Branding Subfolder which is under Images folder).

Figure 4: Adding SharePoint Images Folder
Now we are ready to add some CSS Files to our project. For that you need to right click on SP2010Branding project node Add then SharePoint “Layouts” Mapped (Refer to Figure 4). Then locate Layouts folder in the solution explorer and under that you will find SP2010Branding sub folder (Added by default) then right click on that SP2010Branding folder and Add then New Folder as shown in Figure 5.

Figure 5: Adding SharePoint mapped folders to store CSS and JS files
Now name the newly added folder as CustomCSSFiles and under that folder add a CSS file named changeribbonbg.css . Here we will add some code to change ribbon back ground image by using CSS. Open the changeribbonbg CSS file and place the following code into it:
body #s4-ribbonrow,
.ms-cui-topBar2 {
  /* default color was #21374c */
  background-image:url('/_layouts/Images/SP2010Branding/background.png');
  min-height:43px;
}
It’s important to keep an eye on how we are referencing the Image. Now we should link this CSS file to our custom master page. In the solution explorer locate and open the CustomBranding.master file and try to find </head> and then add the following line of code just before the </head> tag:
<SharePoint:CssRegistration ID="CssRegistration1" name="/_layouts/SP2010Branding/CustomCSSFiles/changeribbonbg.css" After="corev4.css" runat="server"/>

Adding JavaScript to the Master Page

Let’s add some JavaScript to the solution, go to SP2010Branding subfolder which is under Layouts folder and then add one more sub folder as shown in Figure 5 and name it as CustomJavaScripts. Next step is to add a JavaScript file named sp101.js to the CustomJavaScripts folder. Now open the sp101.js file and paste the following code into it:
alert("JavaScript linked successfully, click OK to see your custom branding !");
Now we will link sp101.js JavaScript file to our custom master page. In the solution explorer locate and open the CustomBranding.master file and try to find <asp:ScriptManager></asp:ScriptManager> then you will find the following line:
<asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true" />
Now replace the above with the following:
<asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true">
  <Scripts>
    <asp:ScriptReference Path="/_layouts/SP2010Branding/CustomJavaScripts/sp101.js"></asp:ScriptReference>
  </Scripts>
</asp:ScriptManager>
If you want to add multiple JavaScript files to the master page, add those scripts to CustomJavaScripts folder in the solution explorer and then in the master page add additional <asp:ScriptReference></asp:ScriptReference> reference tags corresponding to those scripts. If you have followed the post correctly, your solution explorer should look like below.

It’s been a long post I know! But if you are really curious you can deploy the solution, you will find the custom master page in the site that you have deployed the solution to. But you have to manually change the master page to see the custom branding/visual difference. I am not a big fan of manual effort. So we will develop a feature to activate the custom branding! Sounds good?
Finally it’s time to write some code, let’s get started. In the solution explorer expand the features section; right click on Feature1 and then Add Event Receiver as shown in the Figure 6.

Figure 6: Adding Event Receiver
Now we will write some code to apply the custom master page when the feature is activated and also we will remove all the custom branding to apply v4.master when the feature is deactivated. Alright, let’s add some flavor to our project! Open the Feature1.EventReceiver.cs file and paste the following methods into it:
// Uncomment the method below to handle the event raised after a feature has been activated.
 
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
  using (SPWeb curWeb = properties.Feature.Parent as SPWeb) {
    Uri masterUri = new Uri(curWeb.Url + "/_catalogs/masterpage/CustomBranding.master");
    curWeb.MasterUrl = masterUri.AbsolutePath;
    curWeb.CustomMasterUrl = masterUri.AbsolutePath;
    curWeb.UIVersion = 4;
    curWeb.Update();
  }
}
 
// Uncomment the method below to handle the event raised before a feature is deactivated.
 
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
  using (SPWeb curWeb = properties.Feature.Parent as SPWeb) {
    Uri masterUri = new Uri(curWeb.Url + "/_catalogs/masterpage/v4.master");
    curWeb.MasterUrl = masterUri.AbsolutePath;
    curWeb.CustomMasterUrl = masterUri.AbsolutePath;
    curWeb.Update();
  }
}
Updating the CustomMasterUrl property is important only in publishing sites that contain publishing pages inside the Pages document library. The CustomMasterUrl property is used to reassign the master page for publishing pages. Assigning a new value to the CustomMasterUrl property in a SharePoint Foundation site has no effect nor does it cause any problems.
One last piece of information that I would like to share is feature scopes. There are 4 different levels of scopes that are available in SharePoint 2010 and they are described in the following table.
ScopeDescription
WebA Web Site scoped Feature is the one that can be activated only at the individual web site level and is specific to that particular web site.
SiteA Site Collection scoped Feature is the one that can be activated at the site collection level and contains all web sites in a site collection as a whole.
WebApplicationA Web Application scoped Feature is the one that can be activated at the web application level for all the web sites in a web application.
FarmA Farm scoped Feature can be activated at the server farm level for an entire server farm.
Now in the solution explorer double click Feature1, change the Title and Description according to your needs as shown in the Figure 7.

Figure 7: Feature Scope and Description
You can change the scope of the feature if you want to. Most commonly used feature scopes are site and web. For our solution Site/Web scope should suffice!
Site features apply to a whole site collection and can be managed by going to the Site Actions > Site Settings > Site Collection Administration > Site collection Features.
Web features apply to a specific web site and can be managed by going to the Site Actions > Site Settings > Site Actions > Manage Site Features
Wohoo.. We are done. Right click solution and Deploy!
So depending upon the scope that you choose, you can find SP2010 Branding feature either in Site collection features or in Manage Site Features section and you can activate/deactivate the feature to test our solution as shown in the Figure 8.

Figure 8: Activate/Deactivate Feature
Once you activate the feature, ideally you should see the following alert message as shown in Figure 9.

Figure 9: JavaScript Alert on Successful deployment
Click OK and finally you will see the custom branding as shown in the Figure 10. Notice that ribbon has a new back ground image.

Figure 10: Deployed Custom Branding
We successfully finished deploying our branding solution, but it’s just the beginning. To make your SharePoint site attractive you have to edit your master page and CSS files according to your design. I hope you’ve enjoyed my blog post! Feel free to email me if you have any questions.
Please download the attached file to access the SP2010 Branding Solution.



Reference

https://captechconsulting.com/blog/amarender-peddamalku/deploy-sharepoint-2010-branding-farm-solution


 

Deploy Master Page using Visual Studio Solution Project and Set it as Default Master Page

Deploy Master Page using Visual Studio Solution Project and Set it as Default Master Page



how to add a master page using a Visual Studio solution project. Also setting the same master as a default for site.

STEP 1 : Adding a Master Page using Module
  1. Open a visual studio 2010
  2. Add new project
  3. Empty Sharepoint Project > Deploy as Farm Solution > Finish.
  4. Add New Item > Select "Module" > I named it as "MasterPage".
  5. Delete the "Sample.txt" which gets added in the module by default.
  6. Add new MainMasterPage.master. Do whatever change you want to it.
  7. Open the elements.xml file of "MasterPage" module. You will have to make some modification shown below.


    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Module Name="MasterPage" List="116" Url="_catalogs/masterpage">
            <File Path="MasterPage\MainMasterPage.master" Url="MainMasterPage.master" Type="GhostableInLibrary">
                <Property Type="string" Name="Title" Value="My Main Master Page"/>
            </File>
      </Module>
    </Elements>
  8. Please verify the below given text i made change in the original one. This is MOST IMPORTANT!!!.
    List="116" Url="_catalogs/masterpage"
    Url="MainMasterPage.master" Type="GhostableInLibrary"
  9. Once this is set just deploy the project.


STEP 1.1 : Verify the file got uploaded

  1. Open the site in SharePoint Designer 2010.
  2. All Files > _catalogs > MasterPage
  3. The file should be at this location because if you see the element.xml above in the url we have given the path of "_catalogs/masterpage". That's it we now achieved the first step of adding a master file to the site.



STEP 2 : Apply the page as a default master page

  1. In the visual studio solution project select "Features > Feature1 > Feature1.feature".
  2. Right click "Add event receiver".
  3. Put this code.

    /// <summary>
    /// Set the MainMasterPage.master as default master for site.
    /// </summary>
    /// <param name="properties"></param>
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate
        {
            using (SPWeb _web = ((SPSite)properties.Feature.Parent).RootWeb)
            {
                Uri _siteMaster = new Uri(string.Format("{0}/_catalogs/masterpage/MainMasterPage.master", _web.Url));
                _web.MasterUrl = _siteMaster.AbsolutePath;
                _web.CustomMasterUrl = _siteMaster.AbsolutePath;
                _web.Update();                   
            }
        });
    }
  4. Right click the project and deploy the solution.

I hope this helps you with the deployment of master page and setting it as a default.

PROBLEM :- There is a problem with the current process. For the first time this will work but if you make any changes to the master page and re-deploy the same solution will not deploy this new master page with the changes on the server. Please read my next blog "Sharepoint 2010 Master page issue with re-deployment with new changes from Visual Studio solution" for the solution.


One step remaining.The developer must go into SharePoint Designer and set the new master as the default master. This cannot be accomplished in the deployment in VS.

Reference

http://maulikdhorajia.blogspot.in/2011/09/sharepoint-2010-deploy-master-page.html

 

Deploying a custom master page in SharePoint 2010


Deploying a custom master page in SharePoint 2010

Today I created a Module. A module can be used to deploy files to your SharePoint environment and the scenario I came up with was to use a module to deploy a master page.
  • I started out by creating an Empty SharePoint project. This can have any name you like and it can be both a farm and a sandboxed solution
  • Next add an new item to the project and choose a module
  • You can rename the module if you want to, I will leave the name at Module1
  • 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.
Project structure
Project structure after adding a module and renaming the sample file to sample.master
I’m not a designer, so I wasn’t interested in creating a brilliant new design (good job, because I wouldn’t be able to do that!).
For the purpose of this example I just took the standard SharePoint 2010 master page contents.
  • Open up SharePoint Designer and open the site you are working on
  • Choose Master Pages on the left side
  • Open v4.master
Don’t let SharePoint fool you. There is a default.master, but this is the old SharePoint 2007 master page that is used if you perform a visual upgrade. When creating a site in SharePoint 2010 the master page that will be used by default is v4.master. I know it’s a bit confusing, but if you have been working with SharePoint for a while you won’t be surprised by this.
  • Copy the contents of v4.master and past them in your sample.master file in Visual Studio. Make the changes you want to.
  • Note how the elements.xml file has changed to reference the sample.master rather than the sample.txt
Contents of the elements.xml file 
The contents of the elements.xml file
  • 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.
  • 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.
  • 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.

[Update 10/12/2010]: Code updated because of improperly disposed SPSite and SPWeb objects. Thanks Donald Hessing and Rhys for pointing it out.

featurereceiver2 
Code used in the feature receiver
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.
Changing the master page using the SharePoint UI
Changing the master page using the SharePoint user interface
 


Reference

http://sharepointchick.com/archive/2010/03/26/deploying-a-custom-master-page-in-sharepoint-2010.aspx