Feature Name: NDPTemplate1
Class Library Name: NDPTemlate1.dll
1.建立dll, 项目命名为NDPTemplate1
2.引入Microsoft.SharePoint
3.加入Template,Features,NDPTemplate1文件夹, 层次为:Template\Features\NDPTemplate1
4.在NDPTemplate1文件夹中加入feature.xml,elements.xml
5.为两个xml文件引入架构,路径"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\XML\wss.xsd"
6.完成feature.xml,elements.xml的内容(wss架构,Module,File结点)
feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="99A54BEF-C670-460e-944B-AA57DA5F036A"
Title="NDPTemplate1"
Scope="Web"
Version="1.0.0.0"
ReceiverAssembly="NDPTemplate1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=112abb48695fd913"
ReceiverClass="NDPTemplate1.FeatureReceiver"
>
<ElementManifests >
<ElementManifest Location ="elements.xml"/>
</ElementManifests>
</Feature>
elements.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
</Elements>
7.加入FeatureReceiver类,实现抽象类方法,完成FeatureAction事件
class FeatureReceiver:SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
Property.RootSite = web.Site;
WikiPage wikiP = new WikiPage();
wikiP.CreateWikiWeb();
Document doc = new Document();
doc.CreateDocs();
Hisoft hi = new Hisoft();
hi.CreateHisoftWeb();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
foreach (SPWeb web1 in web.Webs )
{
foreach (SPWeb web2 in web1.Webs )
{
web2.Delete();
}
web1.Delete();
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
throw new NotImplementedException();
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
throw new NotImplementedException();
}
}
8.Build项目
9.完成gacutil.bat使NDPTemplate1.dll加入gac,从c:\windows\Assembly中找到NDPTemplate1, 获得PublicKeyToken的值,修改feature.xml中的公钥
gacutil.bat:
@set GACUTIL="C:\Windows\Microsoft.NET\Framework\v1.1.4322\gacutil.exe"
%GACUTIL% -i bin\Debug\NDPTemplate1.dll
10.Build项目
11.Install.bat[就是将整个NDPTemplate1文件夹拷贝到c:\..\12\Template\Features下]
Install.bat:
@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
Echo Copying files
xcopy /e /y TEMPLATE\* %TEMPLATEDIR%
Echo Installing feature
%STSADM% -o installfeature -filename Feature1\feature.xml -force
IISRESET
12.激活Feature
13.找bug