Custom Site definition with custom masterpage

Site definition can be considered as a  blueprint of a SharePoint site. When developing business solutions on WSS platform sometimes we will have to create our own site definitions to incorporate functional business modules. Site Definitions gives you lots of flexibility in terms of maintaining and upgrading your solutions compared to Site Templates. Its also gives us the flexibility of choosing custom layouts and the ability to pre program the sequence of the feature activation order when  you create a new site based on the definition.

To create a site definition follow given steps:

1)  Open Visual Studio 2010, click New on the File menu, and then click Project. In the Templates pane, select the Site Definition project template under SharePoint 2010 templates folder. In the Name box, provide a name for your solution. In the Name box, input DemoSiteDefs and then click OK (See below Figure).



2) At this point, the SharePoint Customization Wizard will appear (See below screenshot).You will see a SharePoint Customization Wizard asking for a local site for debugging and deployment. Enter the URL for the SharePoint server site where you want to debug the site definition, or use the default location (http://system name/). Select Deploy as a farm solution for "What is the trust level for this SharePoint solution?" Click Finish. The project appears in Solution Explorer.


A new solution will be created as shown in the image below. Note that two .xml files are created (WebTemp_DemoSiteDefinition.xml, ONet.xml). As well, Features and Package folders are created. (See Below Figure)



3) Add MasterPage Module: To do this, right-click the project node in Solution Explorer, point to Add, and then click New Item.Within the Add New Item dialog box, in the list of SharePoint templates, select Module. Give the module a name, input MasterPageModule. In the module, delete the default Sample.txt file.

Download starter master page from http://startermasterpages.codeplex.com/.

Add the master page under the masterpage module. To do this, select the module node and then, on the Project menu, click Add Existing Item. Locate the master page and select it. Master page files have a .master file name extension. I added MyCustom.master file. See the following figure.



Now double click on element.xml file and replace the below code:

Note: Please note that feature id should be replaced with your project feature id.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MasterPageModule" Url="_catalogs/masterpage" List="116" RootWebOnly="FALSE">
<File Path="MasterPageModule\MyCustom.master" Url="MyCustom.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="FALSE"/>
</Module>
</Elements>


Open the Onet.xml file and place the code:

<?xml version="1.0" encoding="utf-8"?>
<Project Title="DemoSiteDefinition" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
<NavBars>
<NavBar
Name="$Resources:core,category_Top;"
Separator="&amp;nbsp;&amp;nbsp;&amp;nbsp;"
Body="&lt;a ID='onettopnavbar#LABEL_ID#' href='#URL#' accesskey='J'&gt;#LABEL#&lt;/a&gt;"
ID="1002" />
<NavBar
Name="$Resources:core,category_Documents;"
Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;"
Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;"
Suffix="&lt;/table&gt;"
ID="1004" />
</NavBars>
<ListTemplates>
<ListTemplate
Name="meetings"
DisplayName="$Resources:xml_onet_mwsidmeetingDisp;"
Type="200"
BaseType="0"
Unique="TRUE"
Hidden="TRUE"
HiddenList="TRUE"
DontSaveInTemplate="TRUE"
SecurityBits="11"
Description="$Resources:xml_onet_mwsidmeetingDesc;"
Image="/_layouts/images/itevent.gif">
</ListTemplate>
<ListTemplate
Name="agenda"
DisplayName="$Resources:xml_onet_mwsidagendaDisp;"
Type="201"
BaseType="0"
FolderCreation="FALSE"
DisallowContentTypes="TRUE"
SecurityBits="11"
Description="$Resources:xml_onet_mwsidagendaDesc"
Image="/_layouts/images/itagnda.gif">
</ListTemplate>
</ListTemplates>

<DocumentTemplates>
<DocumentTemplate
Path="STS"
DisplayName="$Resources:core,doctemp_Word;"
Type="121"
Default="TRUE"
Description="$Resources:core,doctemp_Word_Desc;">
<DocumentTemplateFiles>
<DocumentTemplateFile
Name="doctemp\word\wdtmpl.dotx"
TargetName="Forms/template.dotx"
Default="TRUE" />
</DocumentTemplateFiles>
</DocumentTemplate>
</DocumentTemplates>

<Configurations>
<Configuration ID="0" Name="DemoSiteDefinition" CustomMasterUrl="_catalogs/masterpage/mycustom.master"
MasterUrl="_catalogs/masterpage/mycustom.master">
<Lists>
<List
FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101"
Type="101"
Title="$Resources:core,shareddocuments_Title;"
Url="$Resources:core,shareddocuments_Folder;"
QuickLaunchUrl="$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx" />
</Lists>
<SiteFeatures>
<Feature ID="f6924d36-2fa8-4f0b-b16d-06b7250180fa"></Feature>
</SiteFeatures>
<WebFeatures>
<Feature ID="3d3245a5-6277-4dc7-848a-911fe1aa2247"></Feature>
<Feature ID="94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"></Feature>
</WebFeatures>
<Modules>
<Module Name="DefaultBlank" />
</Modules>
</Configuration>
</Configurations>
<Modules>
<Module Name="DefaultBlank" Url="" Path="">
<File Url="default.aspx">
</File>
</Module>
</Modules>
</Project>

Press F5 to run and deploy the project.

Create a Site. In the new Site, you can see the custom master page as shown in the following figure.



To add more components refer to the onet.xml basics :http://msdn.microsoft.com/en-us/library/ms474369.aspx

Thanks for time:)

Comments

  1. […] http://mohitvash.wordpress.com/2011/07/08/custom-site-definition-with-custom-masterpage/ […]

    ReplyDelete
  2. If you have been operating on the internet long enough,
    you may have very likely hheard about report article spinners.

    Folks who do not understand online content material know extremely tiny about write-up article spinners.

    ReplyDelete
  3. I am trying the same in SP2013 with VS 2013 and the master page does not go to the new site.
    I took the id from the site scoped feature (the site definition does not have a feature) that has the module with the master page file and used it in
    But when I create the site collection with it it tells me it is not installed on the farm.

    Where did you get the Guids for the and ?

    ReplyDelete
  4. Hi Ofer,

    Thanks for trying my solution. If you noticed in Onet.xml, I have mentioned three feature Ids:

    Site: f6924d36-2fa8-4f0b-b16d-06b7250180fa
    Web: 3d3245a5-6277-4dc7-848a-911fe1aa2247
    Web: 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb

    But same may not be case with you I have picked these feature Ids from Project custom features. If you don't have any custom feature you can leave it blank. Hope it will work for you.

    Regards
    Mohit

    ReplyDelete
  5. Sweet blog! I found it while searching on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I've been trying for a while but I never seem to get there!

    Appreciate it

    ReplyDelete

Post a Comment

Popular posts from this blog

Hide Ribbon on SharePoint 2013 using CSS

Get Comment Count in SharePoint

Configure external site as content sources in sharepoint search