Clinton's profileCherry BytesBlogListsGuestbookMore Tools Help
    July 06

    Custom Site Definitions in MOSS

    In SharePoint 2007 there are 2 different ways to create a custom site definition - the first is to create one based on an existing definition and the second way is to create a definition using code. A custom site definition will give you a base layout which your user will have automatically created for them when they create a new web using your site definition.

    The first method is very quick and easy - simply go into a site which you like the look of, go to site settings and and select 'Save Site as Template' - which is great if you have a customized team site you want other's to be able to use, or even for doing backups. Unfortunately this method just creates a ghosted version of your site, and so for future upgrading of your template is not very effective.

    The second approach, will require a little bit more work - but is far more effective as it offers more flexibility and can be changed more easily once sites have been created based on the definition. It also takes a bit of time to explain and do - hence a slightly longer post here.

    The first step you will need to do is create an xml file in the %HIVE%\1033\XML folder. The file should be prepended with webtemp, so you might end up with a file called something like WebTempClintonsCustomSite.xml. To this add some xml to define your new site definition.

    <?xml version="1.0" encoding="utf-8"?>
    <!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
    <!-- _LocalBinding -->
    <Templates xmlns:ows="Microsoft SharePoint">
     <Template Name="CLINTONSCUSTOMSITEDEF" ID="10015">
        <Configuration ID="0" 
                       Title="Clintons Custom Site" 
                       Hidden="FALSE" 
                       ImageUrl="/_layouts/images/blankprev.png" 
                       DisplayCategory="Clinton"
                       AllowGlobalFeatureAssociations="False" 
                       Description="This template is used for initializing a custom workspace." > 
        
        </Configuration>
     </Template>
    </Templates>

    For more information on what you should use for these attributes it is worth Googling custom site definitions. A few examples of sites which can tell you more are here and here.

    Once you have created this you will need to create your new definition in the %HIVE%\SiteTemplates\ directory. Depending on what type of site definition you are creating, it is generally worth copying and pasting one of the other existing definitions from within this folder and renaming to your own (eg %HIVE%\SiteTemplates\ClintonsDefinition). For example if you wanted to create a new version of a team site, then you would copy the contents of 'STS'. For this example I am going to create a publishing site definition, so I have copied the 'Publishing' folder contents.

    There are really only 2 main files in this definition. The default.aspx page determines the default layout for the page. As I am using a publishing layout, this then uses my default page layout (which for me is WelcomeLinks.aspx - but modifying this is another article!) - which means I don't really have to do anything with this file.

    The main file that you will need to modify though is the ONET.xml file. There are all types of elements you can modify in here - so you will often find that you will need to take bits and pieces from various site definitions to build up the definition that you want for your file.

    The 2 main areas I find myself modifying in this file are the configuration area and the modules area. The configuration area defines what features are installed with the site. The modules define what modules are created when the site is created (for example announcements) as well as any default content to create. I have included a couple of custom samples at the end of this article to illustrate how these might be created. You will also notice that within the configuration section there is a reference to the module that the configuration is going to use.

    In my sample I have created a announcement and links list which appear on the home page of the new site. The configuration element 'Lists' defines the lists to ad. In the module I specify to create these in the 'RightColumnZone' by using a view. They will appear in that zone which is based on my publishing layout.

    The various features that I have chosen to add to the configuration are based on information that I could find from the web, and from existing site definitions. As soon as I work out what a feature does I try to add a comment so as I know what that particular feature is used for.  

    Another point to note is as this is a publishing page, you can set the status of the file you are publishing. In the module section I have set the status of the default.aspx page to 'approved'. You could set this to 'draft' if you wanted the new site custodian to approve and finalize this page before users can access it.

    All in all, creating sites this way is definitely the best way to go - though it certainly takes some fiddling around - and a fair amount of trial and error testing. I tend to modify the files in the actual hive, do an IISReset then a test deploy - then repeat the process - until I get it right. Once it is right though, I use a solution to deploy the site definition to the web. I have also included a sample manifest.xml file which shows the definition for this solution.

    A sample configuration:

     <Configuration ID="0" Name="ClintonSample">
              <Lists>
                  <List FeatureId="00BFEA71-D1CE-42de-9C63-A44004CE0104" Type="104" Title="$Resources:core,announceList;" Url="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;" />
                  <List FeatureId="00BFEA71-2062-426C-90BF-714C59600103" Type="103" Title="$Resources:core,linksList;" Url="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" />
              </Lists>
              <Modules>
                  <Module Name="ClintonModule" />
              </Modules>
              <SiteFeatures>
                  <!-- BasicWebParts Feature -->
                  <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
                  <!-- Publishing Prerequisites-->
                  <Feature ID="A392DA98-270B-4e85-9769-04C0FDE267AA" />
                  <!-- Office Sharepoint Server Publishing -->
                  <Feature ID="F6924D36-2FA8-4f0b-B16D-06B7250180FA" />
                  <!-- Three-state Workflow Feature -->
                  <Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
              </SiteFeatures>
              <WebFeatures>
                  <!-- Include the common WSSListTemplateFeatures used by CMS -->
                  <Feature ID="00BFEA71-DE22-43B2-A848-C05709900100" > </Feature>
                  <Feature ID="00BFEA71-E717-4E80-AA17-D0C71B360101" > </Feature>
                  <Feature ID="00BFEA71-52D4-45B3-B544-B1C71B620109" > </Feature>
                  <Feature ID="00BFEA71-A83E-497E-9BA0-7A5C597D0107" > </Feature>
                  <Feature ID="00BFEA71-4EA5-48D4-A4AD-305CF7030140" > </Feature>
                  
                  <!-- TeamCollab Feature -->
                  <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
                  
                  <!-- MobilityRedirect -->
                  <Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4" />
    
                  <!-- Publishing -->
                  <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
                      <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
                          <Property Key="ChromeMasterUrl" Value=""/>
                          <Property Key="WelcomePageUrl" Value="$Resources:cmscore,List_Pages_UrlName;/default.aspx"/>
                          <Property Key="PagesListUrl" Value=""/>
                          <Property Key="AvailableWebTemplates" Value=""/>
                          <Property Key="AvailablePageLayouts" Value=""/>
                          <Property Key="SimplePublishing" Value="true" />
                      </Properties>
                  </Feature>
                  <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">
                      <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
                          <Property Key="InheritGlobalNavigation" Value="true"/>
                          <Property Key="ShowSiblings" Value="true"/>
                          <Property Key="IncludeSubSites" Value="true"/>
                      </Properties>
                  </Feature>
                  
                   <!-- Office SharePoint Server Publishing -->
                  <Feature ID="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" />
              </WebFeatures>
          </Configuration>     

    A sample module:

      <Modules>
          <Module Name="ClintonModule" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">
              <File Url="default.aspx" Type="GhostableInLibrary" Level="Approved" >
                  <Property Name="Title" Value="$Resources:cmscore,IPPT_HomeWelcomePage_Title;" />
                  <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/WelcomeLinks.aspx, ~SiteCollection/_catalogs/masterpage/WelcomeLinks.aspx" />
                  <Property Name="ContentType" Value="$Resources:cmscore,contenttype_welcomepage_name;" />
                  <View List="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;" BaseViewID="3" WebPartZoneID="RightColumnZone" WebPartOrder="1" />
                  <View List="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" BaseViewID="3" WebPartZoneID="RightColumnZone" WebPartOrder="2" />
                  <AllUsersWebPart WebPartZoneID="RightColumnZone" WebPartOrder="3">
                      <![CDATA[
                       <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
                          <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                          <TypeName>Microsoft.SharePoint.WebPartPages.MembersWebPart</TypeName>
                          <Title>$Resources:wp_Members;</Title>
                          <Description>$Resources:wp_Members_Desc;</Description>
                          <FrameType>Standard</FrameType>
                          <IsVisible>false</IsVisible>
                          </WebPart>
                       ]]>
                  </AllUsersWebPart>
              </File>
          </Module>

    Sample manifest.xml file to deploy solution:

    <?xml version="1.0" encoding="utf-8" ?>
    <Solution  SolutionId="CFEBA622-799C-4e1b-995A-5D390CBE4700" xmlns="http://schemas.microsoft.com/sharepoint/">
        <TemplateFiles>
            <TemplateFile Location="1033\XML\WebTempClintonsCustomSite.xml"/>
            <TemplateFile Location="SiteTemplates\ClintonsDefinition\default.aspx"/>
            <TemplateFile Location="SiteTemplates\ClintonsDefinition\XML\ONET.XML"/>
        </TemplateFiles>
    </Solution>

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://clintcherry.spaces.live.com/blog/cns!AEC0DCBC460E45B9!456.trak
    Weblogs that reference this entry
    • None