比如可以把一个学生管理功能(包括aspx页面等)开发成一个feature,然后可以在不同的moss网站中有选择的激活这个feature,激活后就把对应的链接加入此网站的首页上,以此实现功能的动态加载。
为了方便说明,先列出我的文件结构:
Feature.dll
Install.bat
Template
--Student
--elements.xml
--feature.xml
--Student
--StudentList.aspx
--UserEdit.aspx
首先我们在sharepoint designer中定制两个aspx页面:StudentList.aspx和UserEdit.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>
<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[i].Title == "学生管理")
{
// delete node
topNav[0].Children[i].Delete();
}
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
}
代码没什么特殊的地方,就是使用了MOSS的object model进行操作{
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[i].Title == "学生管理")
{
// delete node
topNav[0].Children[i].Delete();
}
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
}
最后就是进行部署了
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
16
17
第六行注册GAC2@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
16
17
第九行复制文件
12行安装feature
安装好之后在需要的网站上激活这个feature就可以了
0
0
移动互联网产品设计的原则
Java 笔记10
Get Android Source Code
Spinner Animation
Java 笔记09
Java 笔记07
Java 笔记08
例题
例题