在MOSS中开发一个模块化的feature

 

moss中的feature功能很强大,本文主要看一下如何开发一个模块化的feature
比如可以把一个学生管理功能(包括aspx页面等)开发成一个feature,然后可以在不同的moss网站中有选择的激活这个feature,激活后就把对应的链接加入此网站的首页上,以此实现功能的动态加载。
首先我们在sharepoint designer中定制两个aspx页面:StudentList.aspxUserEdit.aspx
  (
要保证这两个页面在moss站点中是能够正常访问的)
  
我这里只是演示feature的功能,就两个页面的代码就不列出了。
然后就是feature配置文件的写法
对于MOSS中的feature我们一般都要写两个配置文件:
<Feature
Id="4292625E-5811-47a4-9B88-58A206C53515"
Title="
学生管理-测试"
Description="
学生管理-测试。"
Scope="Web"
Hidden="false"
ReceiverAssembly="Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=48fca413ed4dd464"
ReceiverClass="Feature.StudentFeature"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
  
其中ReceiverAssemblyReceiverClass是指定feature激活等操作时对应的代码文件的,后面会提到
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Path
指的是Template/Features下的实际路径 Url指的是MOSS站点的虚拟路径 -->
<Module Path="Student" Url="Student" >
<!--
一览页面 -->
<File Url="StudentList.aspx"  Type="Ghostable" />
<!--
编辑页面 -->
<File Url="UserEdit.aspx" Type="Ghostable" />
</Module>
</Elements>
  
特别要注意的是我文件中的注释
然后就是Feature对应的Receiver代码
主要作用是在feature激活时把链接加到网站首页上,在停止时把feature对应的aspx页面从网站中删除(激活feature时会根据配置自动把文件复制到MOSS网站里)
  public class StudentFeature : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
// get a hold off current site in context of feature activation
            SPWeb site = (SPWeb)properties.Feature.Parent;
SPNavigationNodeCollection topNav = site.Navigation.QuickLaunch;
// create dropdown menu for custom site pages
            topNav[0].Children.AddAsLast(new SPNavigationNode("
学生管理", "Student/StudentList.aspx"));
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWeb site = (SPWeb)properties.Feature.Parent;
// delete folder of site pages provisioned during activation
            SPFolder sitePagesFolder = site.GetFolder("Student");
sitePagesFolder.Delete();
SPNavigationNodeCollection topNav = site.Navigation.QuickLaunch;
for (int i = topNav[0].Children.Count - 1; i >= 0; i--)
{
if (topNav[0].Children.Title == "
学生管理")
{
// delete node
                    topNav[0].Children.Delete();
}
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
}

代码没什么特殊的地方,就是使用了 MOSS object model 进行操作
最后就是进行部署了
1@SET TEMPLATEDIR="c:/program files/common files/microsoft shared/web server extensions/12/Template/Features"
2@SET STSADM="c:/program files/common files/microsoft shared/web server extensions/12/bin/stsadm"
3@SET GACUTIL="c:/Program Files/Microsoft Visual Studio 8/SDK/v2.0/Bin/gacutil.exe"
4
5Echo Installing CustomSitePages.dll in GAC
6%GACUTIL% -if Feature.dll
7
8Echo Copying files to TEMPLATE directory
9xcopy /e /y TEMPLATE/* %TEMPLATEDIR%
10
11Echo Installing feature
12%STSADM% -o installfeature -filename  Student/feature.xml -force
13
14IISRESET
15REM cscript c:/windows/system32/iisapp.vbs /a "SharePointDefaultAppPool" /r
  
安装好之后在需要的网站上激活这个 feature 就可以了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值