Saturday, 20 April 2013

Sharepoint 2010 Master Page Customization

                              
In Sharepoint 2010 Master Page Customization Excercise ,you will customize a master page ,and use it for your own content pages.
  • Create a master page and Visual WebPart for Master page.
  • Create a contentpage.
  • Set our content page as Home page.
  • Set our master page as default master page.

     
    Task-I Create a Master page in share point master page customization

  • Open Visual Studio 2010 by going to Start Menu | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  • From the menu, select File | New | Project.
  • In the New Project dialog window, choose Visual C# | SharePoint | 2010 from the Installed Templates.
  • Select Module from the Items.

     


    • Enter MASTERMODULE-Ex1 in the Name textbox .
  • Click OK.
  • Rename Sample.txt to CustomMaster.master.
  • Insert the bellow code to CustomMaster.master.
<%@Master language="C#"%>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="MUISelector" src="~/_controltemplates/MUISelector.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
<html runat="server">

<head runat="server">
<meta name="GENERATOR" content="Microsoft SharePoint">
    <meta name="progid" content="SharePoint.WebPartPage.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Expires" content="0">
    <SharePoint:RobotsMetaTag runat="server"/>
    <title id="onetidTitle"><asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server"/></title>
    <SharePoint:CssLink runat="server"/>
    <SharePoint:Theme runat="server"/>
    <SharePoint:ULSClientConfig runat="server"/>
    <SharePoint:ScriptLink language="javascript" name="core.js" defer="true" runat="server"/>
    <SharePoint:CustomJSUrl runat="server"/>
    <SharePoint:SoapDiscoveryLink runat="server"/>
    <SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
</head>
<body id="masbody" runat="server">
<style type="text/css">
body{
  margin:0;
  padding:header-<length> 0 footer-<length> 0;
 }

div#header{
  position:absolute;
  top:0;
  left:0;
  width:100%;
  height:header-<length>;
 }

div#footer{
  position:absolute;
  bottom:0;
  left:0;
  width:100%;
  height:footer-<length>;
</style>
 <form runat="server" onsubmit="if (typeof(_spFormOnSubmitWrapper) != 'undefined') {return _spFormOnSubmitWrapper();} else {return true;}">
  
   <div id="header">
<header>
<h1  style="background-color:Orange; text-align:center" >Welcome To Anandan Blog</h1>
</header>
</div>
    <asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server">
            <table class="ms-bannerframe" border="0" cellspacing="0" cellpadding="0" width="100%">
           <tr>
            <td class="ms-banner" colspan="2">
     <a href="#" tabindex="-1" style="display:none"></a><a href="#" tabindex="-1" style="display:none"></a>
            </td>
            <td valign="bottom" align="right" style="position:relative;bottom:0;left:0;">
             <table cellpadding="0" cellspacing="0" border="0">
              <tr>
               <td>
                <table height="100%" class="ms-siteaction" cellpadding="0" cellspacing="0">
                 <tr>
                       <td class="ms-siteactionsmenu" id="siteactiontd">
                       <SharePoint:SiteActions runat="server" accesskey="<%$Resources:wss,tb_SiteActions_AK%>" id="SiteActionsMenuMain"
                        PrefixHtml="&lt;div&gt;&lt;div&gt;"
                        SuffixHtml="&lt;/div&gt;&lt;/div&gt;"
                        MenuNotVisibleHtml="&amp;nbsp;">
                        <CustomTemplate>
                        <SharePoint:FeatureMenuTemplate runat="server"
                            FeatureScope="Site"
                            Location="Microsoft.SharePoint.StandardMenu"
                            GroupId="SiteActions"
                            UseShortId="true"
                            >
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_Create"
                                Text="<%$Resources:wss,viewlsts_pagetitle_create%>"
                                Description="<%$Resources:wss,siteactions_createdescription%>"
                                ImageUrl="/_layouts/images/Actionscreate.gif"
                                MenuGroupId="100"
                                Sequence="100"
                                UseShortId="true"
                                ClientOnClickScriptContainingPrefixedUrl="if (LaunchCreateHandler('All')) { STSNavigate('~site/_layouts/create.aspx') }"
                                PermissionsString="ManageLists, ManageSubwebs"
                                PermissionMode="Any" />
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_EditPage"
                                Text="<%$Resources:wss,siteactions_editpage%>"
                                Description="<%$Resources:wss,siteactions_editpagedescription%>"
                                ImageUrl="/_layouts/images/ActionsEditPage.png"
                                MenuGroupId="100"
                                Sequence="200"
                                ClientOnClickNavigateUrl="javascript:ChangeLayoutMode(false);"
                                />
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_Settings"
                                Text="<%$Resources:wss,settings_pagetitle%>"
                                Description="<%$Resources:wss,siteactions_sitesettingsdescription%>"
                                ImageUrl="/_layouts/images/ActionsSettings.gif"
                                MenuGroupId="100"
                                Sequence="300"
                                UseShortId="true"
                                ClientOnClickNavigateUrl="~site/_layouts/settings.aspx"
                                PermissionsString="EnumeratePermissions,ManageWeb,ManageSubwebs,AddAndCustomizePages,ApplyThemeAndBorder,ManageAlerts,ManageLists,ViewUsageData"
                                PermissionMode="Any" />
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_EditSite"
                                Text="<%$Resources:wss,siteactions_editsite%>"
                                Description="<%$Resources:wss,siteactions_editsitedescription%>"
                                ImageUrl="/_layouts/images/SharePointDesigner32.png"
                                MenuGroupId="100"
                                Sequence="310"
                                UseShortId="true"
                                ClientOnClickScriptContainingPrefixedUrl="EditInSPD('~site/',true);"
                                PermissionsString="AddAndCustomizePages"
                                PermissionMode="Any"
                            />
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_SiteWorkflow"
                                Text="<%$Resources:wss,siteactions_siteworkflow%>"
                                Description="<%$Resources:wss,siteactions_siteworkflowescription%>"
                                ImageUrl="/_layouts/images/availableworkflow.gif"
                                MenuGroupId="100"
                                Sequence="400"
                                UseShortId="true"
                                ClientOnClickNavigateUrl="~site/_layouts/workflow.aspx"
                                PermissionsString="EditListItems, AddAndCustomizePages"
                                PermissionMode="Any" />
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_SitePermissions"
                                Text="<%$Resources:wss,people_sitepermissions%>"
                                Description="<%$Resources:wss,siteactions_sitepermissiondescription%>"
                                ImageUrl="/_layouts/images/placeholder32x32.png"
                                MenuGroupId="100"
                                Sequence="500"
                                UseShortId="true"
                                ClientOnClickNavigateUrl="~site/_layouts/user.aspx"
                                PermissionsString="EnumeratePermissions"
                                PermissionMode="Any" />
                            <SharePoint:MenuItemTemplate runat="server" id="MenuItem_PreviewNewUI"
                                Text="<%$Resources:wss,siteactions_previewnewui%>"
                                Description="<%$Resources:wss,siteactions_previewnewuidescription%>"
                                ImageUrl="/_layouts/images/visualupgradehh.png"
                                MenuGroupId="100"
                                Sequence="600"
                                UseShortId="true"
                                ClientOnClickScriptContainingPrefixedUrl="GoToPage('~site/_layouts/prjsetng.aspx')"
                                PermissionsString="ManageWeb"
                                PermissionMode="Any"
                                ShowOnlyIfUIVersionConfigurationEnabled="true" />
                        </SharePoint:FeatureMenuTemplate>
                        </CustomTemplate>
                      </SharePoint:SiteActions></td>
                 </tr>
                </table>
               </td>
              </tr>
             </table>
            </td>
           </tr>
          </table>
        </asp:ContentPlaceHolder>

      
<div id="footer">
<footer>
<h6  style="background-color:Orange; text-align:center" >© Anandan's </h6>
</footer>
 </div>
  </form>
</body>
</html>



  • Add a Visual Web Part.
  • Enter MasterVisualWebpart in the Name textbox .
  • Add the below controls to MasterVisualWebpartUserControl.ascx .




<style type="text/css">
a:hover {color:#FF0000;}
a:link {color:#FF0000;}
</style>
<h1 style="background-color: Orange; text-align: center"> --</h1>
<table>
<tr>
<td>
<h1 style="background-color: #B0E2FF; text-align: center">
<a id="Linkhome" runat="server">Home</a></h1>
</td>
<td>
<h1 style="background-color: #B0E2FF; text-align: center">
<a id="Linkproduct" runat="server">Product</a></h1>
</td>
</tr>
</table>








  • Register the MasterVisualWebpartUserControl.ascx with CustomMaster.master.


<%@ Register TagPrefix="wssuc" TagName="masteruc" src="~/_CONTROLTEMPLATES/MASTERPAGE_EX.VWP/MasterVisualWebpart/MasterVisualWebpartUserControl.ascx" %>


  • Insert the below code to place MasterVisualWebpart in CustomMaster.master.
<wssuc:masteruc id="Idmastervwp" runat="server" EnableViewState="false"/>


  • Create a new content placeholder in CustomMaster.master.


<asp:ContentPlaceHolder id="IdPages" runat="server">


</asp:ContentPlaceHolder>


  • Insert the below code into MasterVisualWebpartUserControl.ascx .cs


string url;
SPSite osite =SPContext.Current.Site;
url = osite.RootWeb.Url;
Linkhome.HRef =url+"/Pages/Home.aspx";
Linkproduct.HRef = url + "/Pages/Product.aspx";


  • Under MASTERMODULE-Ex1, In Element.xml add url in module tag as _catalogs/masterpage ,in file tag add type as GhostableInLibrary.




 

Task 2-Content Page creation in share point master page customization
  • Create a new new folder in MASTERPAGE-EX project as Pages.


  • Create a new text file under ContentPageModule.
  • Rename text file as Home.aspx.
  • Insert the below code to Home.aspx.
<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<asp:Content ID="PageHome" ContentPlaceHolderID="IdPages" runat="server">
<h1 style=" background-color:#003333; text-align:center;color:White" >This is Home page</h1>
</asp:Content>







  • Create a another new text file under ContentPageModule.
  • Rename text file as Product.aspx.
  • Insert the below content to Product.aspx.
<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<asp:Content ID="PageHome" ContentPlaceHolderID="IdPages" runat="server">
<h1 style=" background-color:#003333; text-align:center;color:White" >This is Product page</h1>
</asp:Content>



 

  • Under ContentPageModule --> Element.xml in module tag add url as pages,in file tag add type as GhostableInLibrary .


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ContentPageModule" Url="Pages">
<File Path="ContentPageModule\Product.aspx" Url="Product.aspx" Type="GhostableInLibrary" />
<File Path="ContentPageModule\Home.aspx" Url="Home.aspx" Type="GhostableInLibrary" />
</Module>
</Elements>

 
  • Build and Deploy the MASTERPAGE-EX.


Task-3 -Set our content page as Home page in share point master page customization


    • Click Browse



    • Select Home page as your Welcome page.
    • Click Ok.
    • Again Click Ok.
    Task 4-Set our master page as default master page in share point master page customization

     

    • Click Master Page as shown below.
  • Select Custommaster.master as shown below .
  • Click ok.
  • Now open the your Site collection.(eg:http://XXXXXXXXX:12345/sites/Master_Custom)
in a browser.

 
  • Click on Product Link.



End Of the Exercise Sharepoint 2010 Master Page Customization.

Thank You.

No comments:

Post a Comment