sharepoint站点Feature的定制与开发 以及 stsadm 常用命令
?
| 以下是代碼片段: ??? ?stsadm -o backup -url http://spweb/sites/fdp -filename C:\fdp_0216.bak -overwrite stsadm -o restore -url http://spweb/sites/fdp -filename D:\BACKUP\fdp_0216.bak -overwrite |
Set yyyy=%DATE:~0,4%
Set mm=%Date:~5,2%
Set dd=%Date:~8,2%
Set DateStamp=%yyyy%%mm%%dd%
echo %DateStamp%
stsadm -o backup -url http://ad/ -filename e:\backup\%DateStamp%.dat -overwrite
鎖定網(wǎng)站
?
| 以下是代碼片段: ??? ?stsadm -o getsitelock -url http://sdt-help/personal/test stsadm -o setsitelock -url http://sdt-help/personal/test -lock readonly |
?
| 以下是代碼片段: ???? ?stsadm -o uninstallfeature -filename [feature文件夾下]\feature.xml |
addwppack、deletewppack:webpart和*.cab部署和卸載
?
| 以下是代碼片段: ????? 安裝:stsadm -o?addwppack -filename [*.cab文件路徑]\*.cab ???? ?卸載:stsadm -o deletewppack -name *.cab ?????一般情況下,webpart不要直接部署到網(wǎng)站里,用feature部署要好一些 |
?
addsolution、deletesolution:solution部署和卸載
?
| ???? 安裝:stsadm -o addsolution -filename [*.wsp文件路徑]\*.wsp; ?????部署:stsadm -o deploysolution -name *.wsp -allowgacdeployment -immediate ?????刪除:stsadm.exe -o deletesolution -name *.wsp ? |
?
轉(zhuǎn)?sharepoint站點(diǎn)Feature的定制與開發(fā)
對(duì)于Feature,了解sharepoint的人應(yīng)該都很熟悉了,不但控制著sharepoint上大部分功能的運(yùn)用,還可以做功能的擴(kuò)展,好處就在于管理非常的方便。雖然對(duì)于Feature的開發(fā)有很多,如用Feature定制功能菜單,用戶控件方式的webpart等等,但用Feature的激活與停止功能,來執(zhí)行后臺(tái)代碼還是挺有用的,下面就簡(jiǎn)單的介紹這個(gè)例子。
第一步:
打開VS,創(chuàng)建一個(gè)類庫(kù)的項(xiàng)目,命名為“FeatureToRunCode”,
將Class1.cs命名為MyCode.cs。添加引用Microsoft.sharepoint.dll。添加引用using Microsoft.SharePoint;并在MyCode類繼承SPFeatureReceiver。
整個(gè)MyCode.cs代碼如下
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace FeatureToRunCode
{
??? public class MyCode:SPFeatureReceiver
??? {
??????? public override void FeatureActivated(SPFeatureReceiverProperties properties)//當(dāng)激活時(shí)修改網(wǎng)站的標(biāo)題為My Feature is working
??????? {
??????????? SPWeb web = (SPWeb)properties.Feature.Parent;
??????????? web.AllowUnsafeUpdates = true;
??????????? web.Title = "My Feature is working ";
??????????? web.Update();
??????????? web.Close();
?
??????? }
??????? public override void FeatureDeactivating(SPFeatureReceiverProperties properties)//當(dāng)激活時(shí)修改網(wǎng)站的標(biāo)題為首頁(yè)
??????? {
??????????? SPWeb web = (SPWeb)properties.Feature.Parent;
??????????? web.AllowUnsafeUpdates = true;
??????????? web.Title = "首頁(yè)";
??????????? web.Update();
??????????? web.Close();
??????? }
??????? public override void FeatureInstalled(SPFeatureReceiverProperties properties)//當(dāng)Feature被安裝時(shí),
??????? {
?????????? //當(dāng)Feature被安裝時(shí),執(zhí)行代碼
??????? }
??????? public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
??????? {
????????? //當(dāng)Feature被卸載時(shí),執(zhí)行代碼
??????? }
??? }
}
記得加入強(qiáng)名稱,編譯生成FeatureToRunCode.dll。并用Reflector.exe獲取
程序集名:FeatureToRunCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=146ae474b0fd2221
類名:FeatureToRunCode.MyCode
將在后面的feature.xml文件中被用到。
第二步:
開始創(chuàng)建Feature文件。在FeatureToRunCode項(xiàng)目中,創(chuàng)建文件夾Features,在文件夾Features目錄下創(chuàng)建文件夾FeatureToRunCode,在FeatureToRunCode文件夾下創(chuàng)建feature.xml.
feature.xml的代碼如下:
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
???????? Id="E46240B7-8050-47e7-8A12-586C291B346C"
???????? Title="FeatureToRunCode"
???????? Description="用feature管理運(yùn)行后臺(tái)代碼"
???????? Hidden="FALSE"
???????? Scope="Web"
???????? ReceiverClass="FeatureToRunCode.MyCode"
???????? ReceiverAssembly="FeatureToRunCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=146ae474b0fd2221"
???????? >
</Feature>
說明:
在這個(gè)XML文件中,以下關(guān)于Featrue的metadata 包含在Featrue 元素中。(更詳細(xì)的信息請(qǐng)參閱Feature.xml Files)
ID: 一個(gè)GUID,用于唯一標(biāo)識(shí)這個(gè)Feature,可以通過VS生成
Title:Feature 的名字,可以在網(wǎng)站內(nèi)關(guān)于Site Featrues的頁(yè)面中看到。
Description:對(duì)description的描述。
Version:Feature的版本;
Scope:其值可以是Web或Site,它指明了這個(gè)Feature是應(yīng)用于整個(gè)的Site Collection還是僅僅用于單獨(dú)的一個(gè)子站點(diǎn)。
Hidden:值可以是True或False.該設(shè)置指定了這個(gè)Feature是否在Site Feature頁(yè)面上顯示。
DefaultResourceFile: 資源文件名字,Feature依賴它提供其它附加的配置信息。
ReceiverClass:為程序集接收類。
ReceiverAssembly:為接收程序集.
保存。這樣我們的代碼跟Feature文件就已經(jīng)創(chuàng)建好了,接下來就是布署了。
第三步:
布署Feature。先將FeatureToRunCode.dll拖入到GAC里,即c:\WINDOWS\assembly目錄下。
再到項(xiàng)目目錄下的Features目錄下,將FeatureToRunCode文件夾復(fù)制到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES目錄下。
在SharePoint服務(wù)器上打開命令行
輸入命令切換目錄:cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
安裝Feature輸入命令:stsadm -o installfeature -filename FeatureToRunCode\feature.xml。
不要忘了要iisreset一下服務(wù)器。
OK,Feature的部署與開發(fā)已經(jīng)完成。
第四步:
查看成果。打開網(wǎng)站,進(jìn)入網(wǎng)站設(shè)置,進(jìn)入網(wǎng)站管理---->網(wǎng)站功能,可以看到增加了一個(gè)FeatureToRunCode的Feature功能,如下圖:
嗯,是不錯(cuò),趕緊點(diǎn)擊一下激活按鈕,有點(diǎn)激動(dòng),好在,代碼發(fā)揮作用了,網(wǎng)站的標(biāo)題發(fā)生了變化了,變成My Feature is Working了,如下圖:
至此,Feature管理后臺(tái)代碼已經(jīng)完成了!
*Tip
以上為MOSS2007,但本人在WSS3.0中試過installfeature可以成功,但卻不明白在Site Collection Feature里卻找不到剛Install的Feature.但可以通過命令方式激活與反激活剛才程序自定義的feature
stsadm -o activatefeature -name <Feature Folder> -url <Web Url>
stsadm -o deactivatefeature -name <Feature Folder> -url<Web Url>
?
轉(zhuǎn)載于:https://www.cnblogs.com/kasafuma/archive/2011/08/17/2141679.html
總結(jié)
以上是生活随笔為你收集整理的sharepoint站点Feature的定制与开发 以及 stsadm 常用命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IIS 应用程序池设置
- 下一篇: 10、线程文化