Sharepoint中的Feature Stapling功能

在上一篇http://www.cnblogs.com/fanwenxuan/archive/2012/02/15/2353115.html中我介绍了“WebProvisioned”的应用,并且提出了一些疑问。那么对于一下问题的解决方案是什么?

需求: 我现在有一个新的需求,当用户新建“博客”或者“工作组”站点的时候,我要在站点里面新建一个列表;或者说当用户新建“我的站点”的时候,我想要在每个用户自己的站点上加上点东西,怎么办?

我们可以直接去修改站点定义,譬如说修改“工作组”站点的定义文件,当时微软是不建议修改这些文件的。所以我们的方案是使用Feature Stapling功能。我对这个功能的理解是:通过Feature的方式来修改站点定义。他的作用范围是整个Farm。也就是你激活这个Feature Stapling之后,在任何位置新建站点,都会触发你的feature功能。

具体步骤:

1.创建一个”列表定义”的Feature

   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:    <ListInstance Title="FlyFeatureStaper - FlyList0215"
   4:                  OnQuickLaunch="TRUE"
   5:                  TemplateType="107"
   6:                  FeatureId="00bfea71-a83e-497e-9ba0-7a5c597d0107"
   7:                  Url="Lists/FlyTask"
   8:                  Description="Fly task">
   9:    </ListInstance>
  10:  </Elements>

   1:  <Feature xmlns="http://schemas.microsoft.com/sharepoint/" Title="FlyFeatureStaper Feature1" Id="6f4f155e-64a7-467b-9aa9-602e7e3ebdcf" Scope="Web">
   2:    <ElementManifests>
   3:      <ElementManifest Location="FlyList0215\Elements.xml" />
   4:    </ElementManifests>
   5:  </Feature>
这个Feature的范围可以是web,site,或者其他,他的内容可以是Event Handler, Workflow,或者Web Part等等

2.创建一个新的Feature(Scope必须是Farm级别),并且新建一个空的Element文件。

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Title="FlyFeatureStaper Feature2" Id="a30110c8-df7a-4b23-9e14-383cd453a7cb" Scope="Farm">
  <ElementManifests>
    <ElementManifest Location="FlyStapler0215\Elements.xml" />
  </ElementManifests>
</Feature>

Element.xml文件

   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:    <FeatureSiteTemplateAssociation Id="6f4f155e-64a7-467b-9aa9-602e7e3ebdcf"
   4:                                    TemplateName="STS#0"/>
   5:  </Elements>

这里需要注意的是里面的Id和TemplateName两个值。Id表示你要stapling的Feature的Id,这里也就是我的第一个feautre的ID;TemplateName表示要起作用的站点定义。STS#0表示工作组站点。你可以通过“Get-SPWebTemplate” powershell命令来获取所有的站点定义:例如http://virtualizesharepoint.com/2011/06/15/how-to-find-the-template-name-of-sharepoint-site/ 

最后一步,部署Feature。 Feature Stapling需要在Farm Features中激活。

结果:新建工作组站点的时候,会自动创建一个名称为“FlyFeatureStaper - FlyList0215”的任务列表。

更多场景:当你想在“我的站点”中添加一些页面,或者Web Part的时候,可以通过Feature Stapling的方式实现。

更多内容参考:http://sharepointmagazine.net/articles/introduction-to-sharepoint-feature-stapling-part-1

http://www.sharepointnutsandbolts.com/2007/05/feature-stapling.html

posted @ 2012-02-15 20:17  范文轩  阅读(807)  评论(0编辑  收藏  举报