学习Feature的定制与使用
基本概念:
Windows SharePoint Service 3.0的Feature可以看作是一些开启或关闭的插件,每个插件中可以包含一些数据和操作等,这样就可以把基本的网站定制简化为若干插件的组合。比如,可以通过网站管理界面来激活或关闭某些Feature以达到改变网站模板的效果。
Feature的目录:C:\Progrma Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURE
Features实战
1.在Feature文件目录中创建目录"UserInterfaceLightUp"并在其下建立"Feature.xml"文件 //可以在vs中创建XML文件,这样可以得到智能提示,书写起来更方便。
Feature.xml代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="EECB8C12-D641-4695-932C-B51A022394AC"
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>
其中id的GUID可由vs生成(工具--创建GUID)
2.在同目录下创建Lightup.xml文件
Lightup.xml代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Document Library Toolbar New Menu Dropdown-->
<CustomAction Id ="UserINterfaceLightUp.DocLibNewToolbar"
RegistrationType="List"
RegistrationId="101"
GroupId="NewMenu"
Rights="ManagePermission"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="My DocLib New Menu ToolBar Button">
<UrlAction Url="/_layouts/LightupHello.aspx?NewMenu"/>
</CustomAction>
<!-- Document Library Toolbar Upload Menu Dropdown-->
<CustomAction Id="UserInterfaceLightUp.DocLibUploadToolbar"
RegistrationType="List"
RegistrationId="101"
GroupId="UploadMenu"
Rights="ManagePermission"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="My DocLib Upload Menu Toolbar Button">
<UrlAction Url="/_layouts/LightupHello.aspx?UploadMenu"/>
</CustomAction>
<!-- Document Library Toolbar Actions Menu Dropdown-->
<CustomAction Id="UserInterfaceLightup.SiteActionsToolbar"
RegistrationType="List"
RegistrationId="101"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="My DocLib Actions Menu Toolbar Button">
<UrlAction Url="/_layouts/LightupHello.aspx?Actionsmenu"/>
</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>
<!-- Site Setting -->
<CustomAction Id="UserInterfaceLightUp.SiteSettings"
GroupId="Customization"
Location="Microsoft.SharePoint.SiteSettings"
Sequence="106"
Title="My Site Settings Link">
<UrlAction Url="/_layouts/LightupHello.aspx?Customization"/>
</CustomAction>
</Elements>
3.在\TEMPLATE\LAYOUTS目录下添加文件LightupHello.aspx
LightupHello.aspx代码如下
<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>
<%
string clientQuery = Page.ClientQueryString;
if (clientQuery == "NewMenu")
{
Response.Write("You came from the new document menu.");
}
else if (clientQuery == "UploadMenu" )
{
Response.Write("You came fromm the upload menu");
}
else if (clientQuery == "ActionsMenu")
{
Response.Write("You came from the actions menu ");
}
else if (clientQuery == "SiteActions")
{
Response.Write("You came from the Site Actions Menu");
}
else if (clientQuery == "Customization")
{
Response.Write("You came from the Site Settings menu");
}
%>
4.安装并激活Feature
安装:stsadm -o installfeature -name UserInterfaceLightUp
激活:stsadm -o activatefeature -name UserInterfaceLightUp -url http://localhost
重启IIS:iisreset //和写EventHandler一样,每次更新都需要重启IIS才能看到效果