MOSS自定义菜单(Feature)
微软在MOSS中利用Feature的特性,可以将Feature.xml中以特定格式描述的功能部署到MOSS中,这些功能包括工作流,菜单项,网站栏、内容类型...等等。然后可以在MOSS中配置启用或者停用这些功能,由于这个特性不需要进行代码开发,只需要配置Feature.xml和其中指定的另一个xml,方法简单可行。
Feature.xml
Feature.xml内容如下:
<Feature Id="9C20E12C-193B-45c7-87DF-6DA4F2198797"
Title="这是我利用Feature增加的site级别的菜单"
Description="这是我利用Feature增加的site级别的菜单"
Scope="Site"
Hidden="FALSE"
xmlns="http://schems.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
对Feature.xml解释一下:
Id: 是GUID类型标示的唯一值,可以由VS自带的GUID Generator来生成.
Title:是该功能的标题
Description:是对该功能的描述,会显示在界面上。
Scope:是该功能的范围,其值可以是Web或Site,它指明了这个Feature是应用于整个的Site Collection还是仅仅用于单独的一个子站点。
Hidden: 值可以是True或False.该设置指定了这个Feature是否在网站集功能页面上显示
<ElementManifests>:这个元素包含了另一个XML文件的位置,而这个文件包含的<Elements>的内容是Feature要实现的,是feature的元素清单和定义文件。
Elements.xml
下面就介绍Elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="mypage"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="2000"
Title="我的日常工作"
Description="Getting up and going with inline code">
<UrlAction Url ="~site/Pages/request.aspx"/>
</CustomAction>
</Elements>
参考文章: http://msdn.microsoft.com/zh-cn/library/ms460194(v=office.12).aspx
此例列举的是添加自定义导航菜单。
Id:可选属性,类型为 Text。指定自定义操作的唯一标识符。ID 可能是 GUID,也可能是一个独特的词语(例如 "HtmlViewer"
)。
GroupId:可选属性,类型为 Text。标识包含该操作的操作组(例如,"SiteManagement"
)。如果包含在自定义操作组中,则 GroupId 属性的值必须等于 CustomActionGroup 元素的组 ID。
Location:必需属性,类型为 Text。指定操作所在位置的值。此字符串是在页中的 LinkSectionTable 控件上声明的名称。如:Microsoft.SharePoint.SiteSettings(网站设置下),Microsoft.SharePoint.StandardMenu(网站操作下自定义菜单),
Sequence:排序的优先级。
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- create command link site setting page -->
<CustomAction Id="SiteSettings" GroupId="Customization"
Location="Microsoft.SharePoint.SiteSettings"
Sequence="106"
Title="Custom Litware Site Setting Command">
<UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=SiteSettingCommand"/>
</CustomAction>
<!-- Add command to site action dropdow -->
<CustomAction Id="SiteActionsToolbar111111111111"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Litware custom Action"
Description="custom litware site action"
ImageUrl="/_layouts/images/ACL16.GIF">
<UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=SiteActionCommand"/>
</CustomAction>
<!-- Document Library Toolbar New Menu DropDown -->
<CustomAction Id="DocLibNewToolbar"
RegistrationType="List"
RegistrationId="101"
GroupId="NewMenu"
Rights="ManagePermissions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Litware Custom New Command"
Description="THis Command Creates a new Litware doc"
ImageUrl="/_layouts/images/ACL16.GIF">
<UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=NewDocCommand"/>
</CustomAction>
<!-- Document library Toolbar Actions Menu Dropdown -->
<CustomAction Id="DocLibActionsToolbar"
RegistrationType="List"
RegistrationId="101"
GroupId="ActionsMenu"
Rights="ManagePermissions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Litware Command on Document Library"
Description="THis Command Creates a new Litware doc"
ImageUrl="/_layouts/images/ACL16.GIF">
<UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=DocLibCommand"/>
</CustomAction>
<CustomAction Id="ECBItemToolbar"
RegistrationType="List"
RegistrationId="101"
Type="ECBItem"
Location="BugWorkaround:LocationShouldEqualEditControlBlock"
Sequence="106"
Title="Litware ECB item Command">
<UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=SiteSettingCommand"/>
</CustomAction>
</Elements>
其中第一个CustomAction在Site Setting页面中的LOOK AND FEEL标题下创建了一个自定义链接.第二个CustomAction在页面的Site Action菜单下增加了一个用户自定义菜单项.第三个CustomAction在文档库的New下拉菜单下创建了一个自定义菜单项.第四个CustomAction在文档库的Action下拉菜单下创建了一个自定义菜单项.
注意第五个CustomAction本来是在文档库的每个列表项的菜单上增加一个菜单项,
Sharepoint中几乎每个功能都可以通过feature来实现,(feature中最主要的就是:Location和GroupId)
卸载和安装
1.安装
安装功能:stsadm -o installfeature -filename ItemAddEvent/Feature.xml
激活功能:stsadm -o activatefeature -filename ItemAddEvent/Feature.xml -url http://zhangqing:2000/SJ
路径:C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/BIN
2.卸载
停用功能:stsadm -o deactivatefeature -filename ItemAddEvent/Feature.xml -url http://zhangqing:2000/SJ
卸载功能:stsadm -o uninstallfeature -filename ItemAddEvent/Feature.xml