MOSS 2007入门 : 使用Feature定义站点中的菜单项
原文链接:http://tech.it168.com/d/2008-05-28/200805281313310.shtml
【IT168技术文档】
今天就来讲讲feature的使用.在MOSS 2007中feature功能之强大超乎想象,可以说对一个已有的网站功能性的增强最后多数都要通过feature来实现.例如添加webpart,实现 Event Handler等等...今天就做一个使用feature定义网站中的菜单项的Demo.
Step(1):在网站中创建一个页面,存放于一个文档库中,这里我创建的页面在文档库SiteCollectionDocuments下 testpage.aspx,那么这个页面的引用路径就是<%siteurl%> /SiteCollectionDocuments/testpage.aspx .
Step(2):在12\TEMPLATE\FEATURES文件架下新建一个文件夹叫LinkToPage,在文件夹下创建Feature.xml.内容如下.
<?xml version="1.0" encoding="utf-8" ?> <Feature Id="C86A92EA-A5D3-4d65-855C-0557AE5D065A" Title="Link To Page" Description="This example show how to create a menu linke to a customize page!" Version="1.0.0.0" Scope="Site" AlwaysForceInstall="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="LinkToPage.xml" /> </ElementManifests> </Feature>
Feature元素的几个属性说明一下:
Id:这里要使用vs的guid工具生成一个guid,copy过来就可以
Title 和 Description分别是Feature的标题和描述.
Scope这个属性比较重要:是一个枚举值,是用来描述这个feature的作用范围.这里选择:site
AlwaysForceInstall:这个属性设置为true 可以在重复安装这个feature中自动覆盖原来安装的那个相同的feature.
ElementManifest的location属性制定一个描述feature内容的xml文件,这里叫做LinkToPage.xml
Step(3):建立上一步中的LinkToPage.xml,内容如下.
<?xml version="1.0" encoding="utf-8" ?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction Id="LinkToPageInactionsMenu" RegistrationType="List" RegistrationId="101" GroupId="ActionsMenu" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="Link To Page" Description="This is action menu" > <UrlAction Url="~sitecollection/SiteCollectionDocuments/testpage.aspx"/> </CustomAction> <CustomAction Id="LinkToPage" RegistrationType="List" RegistrationId="101" GroupId="NewMenu" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="Link To Page" Description="This is new menu!" > <UrlAction Url="~sitecollection/SiteCollectionDocuments/testpage.aspx"/> </CustomAction> </Elements>
这个xml文件中可以多个CustomAction来描述feature的实际内容,这里采用了两个。
Location和groupid两个属性分别指定该feature是定义了哪两个菜单.
Sequence属性指定新增加的菜单项在这个菜单中的排序,设置的大一点该菜单项排列就靠后.
Title 和 Description分别是该菜单项的标题和描述.
UrlAction属性指定了该菜单项的连接到的页面,当然了,这个demo连接到的是我们在第一步中建立那个页面.这里有一个相对路径的问题,~site 表示站点的主目录, ~sitecollection 表示站点集的主目录.因为我的demo是做在一个站点集下面的,所以采用~sitecollection后面是连接文件的相对路径..
Step(4):下面就是将这个feature部署到站点,因为可能会经常使用到部署feature这样的功能,那么我们写一个通用的bat文件来 实现feature的部署,内容如下.
@rem====================================================================== @rem @rem setupfeature.bat @rem @rem====================================================================== @echo off setlocal pushd . goto InstallFeature @rem---------------------------------------------------------------------- @rem InstallFeature @rem---------------------------------------------------------------------- :InstallFeature set SPAdminTool=%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe set TargetUrl=http://mymoss:8001 set FeaturePath=LinkToPage\Feature.xml echo InstallFeature %FeaturePath% "%SPAdminTool%" -o installfeature -filename %FeaturePath% echo Activating feature %FeaturePath% "%SPAdminTool%" -o activatefeature -filename %FeaturePath% -url %TargetUrl% echo iisreset iisreset
This posting is provided "AS IS" with no warranties, and confers no rights.
浙公网安备 33010602011771号