Feature概述 sharepoint

1. Feature概述

Feature是SharePoint中的一个重要概念,最近几天都在看,一开始比较糊涂,这个Feature到底是什么东东?按照SharePoint SDK做了几个例子后,渐渐的有些了解,在接下来的文章中,我将结合例子把我对Feature的了解写下来。

       关于Feature的好处,在SDK中说了一大堆,通过使用Feature,可以大大简化我们更改或添加SharePoint一些功能的工作量,比如在某个工具条上添加一个按钮,在一个菜单中添加一个菜单项,替换一个现有的Control,创建一些事件处理程序,创建一个客户化的List定义等等。这些Feature管理起来也比较方便。

       那么一个Feature由哪几部分组成呢?Feature是由一个Feature文件(Feature.xml)和一些描述单个Element的文件组成。Feature放置在下面的目录中:

%SystemDrive%/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES

可以看到在上面的目录下有很多子文件夹,每个子文件夹下都有一个Feature.xml文件。你也可以在这里创建自己的文件夹,来创建Feature。在Feature.xml文件中,使用<Feture>标签来标记Feature以及范围等属性,使用< ElementManifests >指定了程序集、文件。

我们可以查看下面的图示来帮助理解这些文件的关系。Feature Element文件根据类型的不同,具有不同的格式。详细可以查看SDK。

 

 

后面以两个简单的例子介绍如何创建Feature。

2. 创建Feature——Custom Action

如果你想在Windows SharePoint Services的工具条上添加一个按钮,或者是想在List工具条以及List Item的菜单中添加一个菜单项,又或者是想在Site Actions下拉菜单中添加一项,你就可以通过创建Feature来实现这些功能。

要想定义一个客户化的菜单动作,你必须设定菜单所在的位置。这个位置可以通过SharePointID来指定。举例来说,要在Site Setting页面中添加一个客户化动作,可以将Location属性设置为Microsoft.SharePoint.SiteSettings,然后通过GroupId设置一个特定的区域,如Galleries表示该页Galleries。关于其他的Location以及GroupId信息可以查看SDKHow to: Add Actions to the User Interface)。

步骤

Step 1: %SystemDrive%/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES目录下创建一个文件夹,如UserInterfaceLightUp

Step 2: 在文件夹UserInterfaceLightUp下,建立一个Feature.xml文件,将以下信息拷贝到文件中。

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="GUID" 
    Title="Light Up"
    Description="This example shows how you can light up various areas inside Windows SharePoint Services."
    Version="1.0.0.0"
    Scope="Site"
    xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="Lightup.xml" />
  </ElementManifests>
</Feature>

Step 3: 创建一个GUID,在刚才创建的Feature.xml文件中,将这个创建的GUID作为Feature Id。创建GUID可以使用guidgen.exeLocal_Drive:/Program Files/Microsoft Visual Studio 8/Common7/Tools)。比较简单的方式是在Start——All Programs下找到Vistual Studio2005,打开Vistual Studio Tools下的Visual Studio 2005 Command Prompt,然后输入guidgen.exe,回车。

Step 4: 在文件夹UserInterfaceLightUp下再创建一个 Lightup.xml文件来定义动作。该例子中,将每个动作的链接指向了同一个网页,并传递一个值来判断是操作的哪个动作。

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Document Library Toolbar Upload Menu Dropdown -->
  <CustomAction Id="UserInterfaceLightUp.DocLibUploadToolbar"
    RegistrationType="List"
    RegistrationId="101"
    GroupId="UploadMenu"
    Rights="ManagePermissions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="1000"
    Title="MY DOCLIB UPLOAD MENU TOOLBAR BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?UploadMenu"/>
  </CustomAction>
<!-- Site Actions Dropdown -->
  <CustomAction Id="UserInterfaceLightUp.SiteActionsToolbar"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="1000"
    Title="MY SITE ACTIONS BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?SiteActions"/>
  </CustomAction>
<!-- Per Item Dropdown (ECB)-->
  <CustomAction 
    Id="UserInterfaceLightUp.ECBItemToolbar"
    RegistrationType="List"
    RegistrationId="101"
    Type="ECBItem" 
    Location="EditControlBlock"
    Sequence="106"
    Title="MY ECB ITEM">
    <UrlAction Url="/_layouts/LightupHello.aspx?ECBItem"/>
  </CustomAction>
<!-- Display Form Toolbar -->
  <CustomAction 
    Id="UserInterfaceLightUp.DisplayFormToolbar"
    RegistrationType="List"
    RegistrationId="101"
    Location="DisplayFormToolbar"
    Sequence="106"
    Title="MY DISPLAY FORM TOOLBAR">
    <UrlAction Url="/_layouts/LightupHello.aspx?DisplayFormToolbar"/>
  </CustomAction>
<!-- Edit Form Toolbar -->
  <CustomAction 
    Id="UserInterfaceLightUp.EditFormToolbar"
    RegistrationType="List"
    RegistrationId="101"
    Location="EditFormToolbar"
    Sequence="106"
    Title="MY EDIT FORM TOOLBAR">
    <UrlAction Url="/_layouts/LightupHello.aspx?EditFormToolbar"/>
  </CustomAction>
<!-- Site Settings -->
  <CustomAction 
    Id="UserInterfaceLightUp.SiteSettings"
    GroupId="Customization"
    Location="Microsoft.SharePoint.SiteSettings"
    Sequence="106"
    Title="MY SITE SETTINGS LINK">
    <UrlAction Url="/_layouts/LightupHello.aspx?Customization"/>
  </CustomAction>
<!-- Content Type Settings -->
  <CustomAction 
    Id="UserInterfaceLightUp.ContentTypeSettings"
    GroupId="General"
    Location="Microsoft.SharePoint.ContentTypeSettings"
    Sequence="106"
    Title="MY CONTENT TYPE SETTINGS LINK">
    <UrlAction Url="/_layouts/LightupHello.aspx?General"/>
  </CustomAction>
</Elements>

 

    Step 5: 在/TEMPLATE/LAYOUTS目录下,添加一个LightupHello.aspx文件,内容此处不写了,总之它的目的是当点击前一步中创建的菜单或按钮时,会链接到该页。
 Step 6:运行Command Prompt(打开Run对话框,输入cmd,按回车),输入cd %SystemDrive%/ Program Files/Common Files/Microsoft Shared/web server extensions/12/BIN,其中SystemDrive是SharePoint所在的系统盘,如c:。定位到上面的目录后,输入
stsadm -o installfeature -filename UserInterfaceLightUp/feature.xml
它的作用是安装Feature。
然后输入
stsadm -o activatefeature -filename UserInterfaceLightUp/feature.xml -url http://Server/Site/Subsite
最后重设IIS使它生效,输入
Iisreset
 Step 7:点击Site Actions查看新的菜单项;点击Site Actions下拉菜单中的SiteSetting,看Look and Feel部分;导航到一个document library,打开Upload菜单看新的添加项;查看document library中Item的菜单项;点击document library中Item菜单的View Properties和Edit Properties,查看工具条上的action。
原文地址:https://www.cnblogs.com/jhabb/p/Sharepoint2010.html