Including Features in Site Definitions


Web-scoped and Site-scoped Features can also be deployed via site definitions. Site definitions form the basis from which to create SharePoint sites. For example, the default Team Site template is created from the default STS site definition. You can create your own custom site definitions to define specific functionality for sites, such as custom lists or content types, and you can add that functionality using Features.

In Windows SharePoint Services 2.0, a major advantage of creating site definitions as opposed to effecting change using FrontPage 2003 was the fact that sites provisioned from site definitions remained ghosted. With ghosted site definitions, the pages and templates in those sites were called directly from the Web front-end server rather than an unghosted version in the database, which resulted from FrontPage 2003 modifications. This resulted in better, overall server performance and end user experience.

Although ghosting and unghosting still exist in SharePoint Server 2007, you can now more easily reghost pages after they have become unghosted through customizations using SharePoint Designer 2007. But an added advantage to working with site definitions in SharePoint Server 2007 is the ability to more easily apply robust functionality using Features, to both new and existing site definitions. Features deployed via a site definition also become automatically activated on sites provisioned from the site definition. This removes the need for any manual or programmatic intervention to separately activate Features after Feature installation.

Note 

The terminology for ghosting and unghosting has changed for SharePoint Server 2007. In SharePoint Server 2007, ghosting is now referred to as uncustomized and unghosting is now referred to as customized.

This section covers how to create a custom site definition and include Web and Site-scoped Features to add a custom document library and content types and columns.

Note 

When sites are deployed based on a site definition containing your custom Features, those Features are automatically activated. However, you still need to have installed those Features before provisioning them as part of your site definition. If you attempt to create a site from a site definition containing a Feature where that Feature has not been installed, you will receive the following error during site creation: "Feature 'GUID' is not installed in this farm, and cannot be added to this scope."

Creating a Custom Site Definition

To demonstrate including and deploying Features as part of a site definition, you'll create a custom site definition named Projects which will be based on the default STS site definition. The default site definitions are located on the Web front-end server, at the following location:

  • %SystemDrive%\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates

Note 

Avoid modifying the default site definitions, such as the default STS site definition. Changes made to the default site definitions are not supported by Microsoft, and you risk losing those changes during future upgrades, including service pack upgrades.

To create the new Projects site definition, complete the following steps.

On the CD 

The Projects site definition is included on the book's CD in the\Code\Chapter 26 folder.

  1. In the SiteTemplates directory, locate the STS site definition folder. Copy and paste that folder to the SiteTemplates directory and rename it to Projects.

    Register the new Projects site definition by creating a Webtemp.xml, or template, file for the site definition. The Webtemp.xml file notifies SharePoint of the site definition and also enables you to configure additional information for the site definition, such as whether the site definition will be hidden or visible in the template picker when creating new sites, a description for the site definition and custom image to be displayed in the template picker when creating new sites. The default Webtemp.xml files are located at the following location:

    • %SystemDrive%\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML

    Note 

    The site definition template files must begin with Webtemp for SharePoint to recognize those files as site definition template files.

  2. To create a Webtemp.xml file for the Projects site definition, create a new file named image from book WebTempProject.xml and include the following code. The ID property in the Template Name attribute should be set to above 1000 to avoid any conflict with the default SharePoint templates. The Template Name value must exactly match the name of the site definition. You can also choose to include a DisplayCategory property as part of the configuration. The DisplayCategory value will be displayed as an additional category from which to choose templates when creating sites-for example, in addition to the default categories of Collaboration, Meetings, and Enterprise.

     <?xml version="1.0" encoding="utf-8" ?> <!-- _lc _version="12.0.4017" _dal="1" --> <!-- _LocalBinding --> <Templates xmlns:ows="Microsoft SharePoint">  <Template Name="PROJECTS" >     <Configuration  Title="Projects Site" Hidden="FALSE"      ImageUrl="/_layouts/images/stsprev.png" Description="This      template creates a site for Project teams to create, organize,      and share information quickly and easily. It includes a Document      Library, and basic lists such as Announcements, Calendar, Contacts,      and Quick Links." DisplayCategory="Projects" > </Configuration>  </Template> </Templates> 

  3. Save the image from book WebTempProject.xml file, and then perform an IISRESET to deploy the new site definition and make it available as a template in the Template Selection section when creating new sites.

Note 

Any changes to the site definition .xml file and related template .xml file necessitate an IISRESET to have those changes implemented.

Adding a Feature to the Site Definition

You can customize sites provisioned from a new site definition by adding in new or custom Features. In this section, you'll add two custom Features to the new Projects site definition; one a Site-scoped Feature, including a ProjectXMeetings content type and columns, and the other a Web-scoped Feature, including a custom Project document library which also includes a custom Resource file.

Each SharePoint site definition includes an image from book ONET.XML file, located in the XML folder under the site definition folder:

  • %SystemDrive%\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\<sitedefinitionfoldername> \xml

The image from book ONET.XML file includes functional directives for the site definition, including navigation, templates and views, references to default List Features, and custom Features, which will be provisioned to sites created from the site definition. You can include both Site Collection-scoped Features and Web-scoped Features in the image from book ONET.XML file.

To reference a custom Feature in the Projects site definition image from book ONET.XML file and have that Feature deployed and activated in sites provisioned from the Projects site definition, complete the following steps:

On the CD 

The following example assumes you have installed the ProjectContentTypes and ProjectDocumentLibrary Features included on the CD in the\Code\Chapter 26 folder in the Visual Studio SharePoint solution. It also assumes you have copied the Resource file, image from book projectdocumentlibrary.en-US.resx, also included on the CD, to the Resources folder on your SharePoint server.

  1. Using Visual Studio or Notepad, open the Projects site definition image from book ONET.XML file and scroll to the section of the file that includes the <SiteFeatures> and <WebFeatures> tags, and the default Features, as shown in the following example:

           <SiteFeatures>         <!-- BasicWebParts Feature -->         <Feature ID="" />       </SiteFeatures>       <WebFeatures>         <!-- TeamCollab Feature -->         <Feature ID="" />       </WebFeatures> 

    Note 

    In this example, because you copied the image from book ONET.XML file from the default STS site definition, the <SiteFeatures> and <WebFeatures> sections are already populated with the default BasicWebParts and TeamCollab Features. You can choose to remove these or leave them if you want to maintain the core functionality offered as part of the STS (Team Site) site definition. The <SiteFeatures> section denotes site collection Features, while the <WebFeatures> section denotes Web Features.

  2. Add a new line to the SiteFeatures section and include the reference to the custom ProjectContentTypes Feature, as shown below:

      <SiteFeatures>         <!-- BasicWebParts Feature -->         <Feature ID="" />         <! - - ProjectContentTypes - ->         <Feature ID=""  </SiteFeatures> 

    In the case of the ProjectContentTypes Feature, we need to add this Feature to the SiteFeatures section of the image from book ONET.XML file because the Feature includes the Content Type and Field Element which cannot be scoped to Web.

  3. Next, add a new line to the WebFeatures section and include the reference to the custom ProjectDocumentLibrary Feature, as shown below:

     <WebFeatures> <!-- TeamCollab Feature --> <Feature ID="" /> <!- - ProjectDocumentLibrary - -> <Feature ID=""> </WebFeatures> 

  4. Save the Projects image from book ONET.XML file and then open the Windows command-line tool, and run an IISRESET.

The Projects site definition now includes two custom Features. When you provision a new site collection based on the Projects site definition, a new content type named ProjectXMeetings will be included in the Site Content Type Gallery of the root site of the site collection. If you click on the ProjectXMeetings content type you'll see that it includes two custom columns, Attendees and Highlights, as defined in the ProjectContentTypes Feature.

The custom Content Type Feature will have been activated during site provisioning but will not be visible on the site's Site Features administration page because this Feature is a hidden Feature, denoted by the Hidden="TRUE" attribute in the ProjectContentTypes image from book Feature.xml file. The custom ProjectDocumentLibrary Feature will also be included on any new sites provisioned from the Projects site definition, as an additional Libraries template named Project Documents. The ProjectDocumentLibrary Feature will be also be visible on the Site Features administration page, which means you can optionally deactivate this Feature following deployment.

Note 

The Feature activation will fail if you included a Feature in your site definition that is dependent on another Feature being activated and that Feature is not activated. For example, if your site definition includes a Web-scoped Feature that is dependent on a Site Collection-scoped Feature being activated and the Site Collection-scoped Feature is not activated, the Web-scoped Feature activation will fail when deployed via the site definition.

Removing a Feature from ONET.XML File

If you remove a Feature reference or tag from the image from book ONET.XML file, new sites provisioned from that site definition will continue to include an activated instance of the Feature until you perform an IISRESET. Once you've performed an IISRESET, after removal of the Feature reference from the image from book ONET.XML file, the Feature remains installed and active on any existing sites created from that site definition as long as the Feature has not been deactivated or uninstalled.

Any sites created from the site definition subsequent to the removal of the Feature reference from image from book ONET.XML and following an IISRESET still include the Feature if the Feature remains installed and scoped for the instance of the sites provisioned. But in this case, the Feature will not be automatically activated. You need to activate the Feature separately, either using the command-line tool or through the administrative user interface page, Site Features.

If you uninstall a Feature where the Feature is referenced in a site definition, the Feature will be uninstalled from all existing sites including those sites created from the site definition. Attempting to provision sites from that same site definition, which still contains the reference to the uninstalled Feature, generates the following error message: "Feature 'GUID' is not installed in this farm, and cannot be added to this scope."

If you subsequently reinstall the same Feature, it will be reinstalled to any existing sites provisioned from the site definition but will not be activated. Any new sites created from the site definition containing a reference to the Feature, once the Feature is reinstalled, will be automatically activated.




Microsoft Office Sharepoint Server 2007 Administrator's Companion
MicrosoftВ® Office SharePointВ® Server 2007 Administrators Companion
ISBN: 0735622825
EAN: 2147483647
Year: 2004
Pages: 299

Similar book on Amazon
Microsoft Office SharePoint Server 2007 Best Practices
Microsoft Office SharePoint Server 2007 Best Practices
Microsoft SharePoint 2010 Administrator's Companion
Microsoft SharePoint 2010 Administrator's Companion
Professional SharePoint 2010 Administration
Professional SharePoint 2010 Administration
Inside Microsoft  Office SharePoint  Server 2007
Inside Microsoft Office SharePoint Server 2007

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net