在新版本的SharePoint中,用户定制的Feature可以默认的增加到站点中。当给Site Definition 增加一个Feature后,那么从这个Site Definition中创建的站点上,这个Feature就会自动可以使用。

这个功能允许开发者创建Features并把它们接入到任何一个Site Definition中。在上一个版本的SharePoint中,现在以Feature的形式发布的功能,需要在每一个使用该功能的Site Definition中注册和配置。现在不需要这样做了,因为Feature封装了所有发布的功能。

将Features加入到Site Definitions

步骤1:

打开Site Definition的ONET.XML

找到为Samle Team Site 配置的那一节,其XML描述如下:

<Configuration ID="0" Name="Default">

      <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" />

        <List FeatureId="00BFEA71-6A49-43FA-B535-D15C05500108" Type="108" Title="$Resources:core,discussions_Title;" Url="$Resources:core,lists_Folder;/$Resources:core,discussions_Folder;" QuickLaunchUrl="$Resources:core,lists_Folder;/$Resources:core,discussions_Folder;/AllItems.aspx" EmailAlias="$Resources:core,discussions_EmailAlias;" />

        <List FeatureId="00BFEA71-D1CE-42de-9C63-A44004CE0104" Type="104" Title="$Resources:core,announceList;" Url="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;">

          <Data>

            <Rows>

              <Row>

                <Field Name="Title">$Resources:onetid11;</Field>

                <Field Name="Body">$Resources:onetid12;</Field>

                <Field Name="Expires">&lt;ows:TodayISO/&gt;</Field>

              </Row>

            </Rows>

          </Data>

        </List>

        <List FeatureId="00BFEA71-2062-426C-90BF-714C59600103" Type="103" Title="$Resources:core,linksList;" Url="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" />

        <List FeatureId="00BFEA71-EC85-4903-972D-EBE475780106" Type="106" Title="$Resources:core,calendarList;" Url="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;" QuickLaunchUrl="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;/Calendar.aspx" EmailAlias="$Resources:core,calendar_EmailAlias;" />

        <List FeatureId="00BFEA71-A83E-497E-9BA0-7A5C597D0107" Type="107" Title="$Resources:core,taskList;" Url="$Resources:core,lists_Folder;/$Resources:core,tasks_Folder;" QuickLaunchUrl="$Resources:core,lists_Folder;/$Resources:core,tasks_Folder;/AllItems.aspx" />

      </Lists>

      <Modules>

        <Module Name="Default" />

      </Modules>

      <SiteFeatures>

        <!-- BasicWebParts Feature -->

        <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />

      </SiteFeatures>

      <WebFeatures>

        <!-- TeamCollab Feature -->

        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />

      </WebFeatures>

</Configuration>

在<SiteFeatures>元素中增加如下的XML以把自己的定制的Document Library Feature加入:

<!-- Custom Common Document Library Feature -->

<Feature ID="<GUID OF YOUR FEATURE GOES HERE>" />

这个GUID和Feature.xml文件中GUID相对应。

步骤2:Reset IIS

步骤3:基于这个增加了Feature的站点定义创建一个新的站点。

创建完毕后在Site Features页面中会看到列表中有Custom Document Library Feature。按 Activeate 按钮可以激活这个Feature,激活后就可以基于这个Feature创建自己定制的Doument Library.

进一步的定制:

上一步实现了在Site Definition中增加Feature,并使它在创建站点的时候可用。现在要实现的一个功能是在创建站点时就从Feture中创建一个Custom Document Library.这样用户就不需要在站点创建完毕后再创建那个定制的Documnent Library.

以下步骤实现了从Site Definition中创建站点时Custom Document Library Feature被默认创建。

步骤1:编辑Site Definition 的ONET.XML文件

在刚刚编辑过的Configuration节的<Lists>元素中增加如下的XML:

<List FeatureId="<GUID OF YOUR FEATURE GOES HERE>"

       Type="4000"

       Title="$Resources:customDocumentLibrary,customDocumentLibrary_Title;"

       Url="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;"

       QuickLaunchUrl="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;/Forms/AllItems.aspx" />

 或者:

<List FeatureId="<GUID OF YOUR FEATURE GOES HERE>"

       Type="4000"

       Title="Custom Document Library"

       Url="Custom Document Library"              

       QuickLaunchUrl="Custom Document Library/Forms/AllItems.aspx" />

步骤2:Reset IIS

步骤3:创建一个基于这个Site Definition 的SharePoint 站点

效果如下

 

更进一步的定制

除了默认创建一个列表,我们还可以在根据Site Definition创建站点时在生成的主页上放置一个Custom Document Library 列表的视图。以下是步骤:

步骤1. 编辑Site Definition 的ONET.xml文件:

找到<Module>节,它是被Configuration 调用的。XML文本就像这样:

<Module Name="Default" Url="" Path="">

      <File Url="default.aspx" NavBarHome="True">

        <View List="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;" BaseViewID="0" WebPartZoneID="Left" />

        <View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;" BaseViewID="0" RecurrenceRowset="TRUE" WebPartZoneID="Left" WebPartOrder="2" />

        <AllUsersWebPart WebPartZoneID="Right" WebPartOrder="1"><![CDATA[

                   <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">

                        <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

                        <TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>

                        <FrameType>None</FrameType>

                        <Title>$Resources:wp_SiteImage;</Title>

                        <iwp:ImageLink>/_layouts/images/homepage.gif</iwp:ImageLink>

                   </WebPart>

                   ]]></AllUsersWebPart>

        <View List="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" BaseViewID="0" WebPartZoneID="Right" WebPartOrder="2" />

        <NavBarPage Name="$Resources:core,nav_Home;" ID="1002" Position="Start" />

        <NavBarPage Name="$Resources:core,nav_Home;" ID="0" Position="Start" />

      </File>

</Module>

 

<Module>元素指明了调用它的Configurations所使用的资源,<File>元素指明了在Configuration中要实现的那些文件。在为default.aspx配置的<File>元素中加入如下的XML以创建一个Custom Document Library列表。

<View List="Custom Document Library" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="3" />

<View List="$Resources:customDocumentLibrary,customDocumentLibrary_Folder;" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="3" />

步骤2: Reset IIS

步骤3:根据Site Definition 创建站点

效果如下图所示:

 

 

注意:一旦通过STSADM.exe 在服务器上安装了某一个Feature则在各个已创建的网站上也可以使用,只是此时在这些网站上这个Feature并没有被激活。激活后即可使用。