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
鎖定網站
?
| 以下是代碼片段: ??? ?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不要直接部署到網站里,用feature部署要好一些 |
?
addsolution、deletesolution:solution部署和卸載
?
| ???? 安裝:stsadm -o addsolution -filename [*.wsp文件路徑]\*.wsp; ?????部署:stsadm -o deploysolution -name *.wsp -allowgacdeployment -immediate ?????刪除:stsadm.exe -o deletesolution -name *.wsp ? |
?
轉?sharepoint站點Feature的定制與開發
對于Feature,了解sharepoint的人應該都很熟悉了,不但控制著sharepoint上大部分功能的運用,還可以做功能的擴展,好處就在于管理非常的方便。雖然對于Feature的開發有很多,如用Feature定制功能菜單,用戶控件方式的webpart等等,但用Feature的激活與停止功能,來執行后臺代碼還是挺有用的,下面就簡單的介紹這個例子。
第一步:
打開VS,創建一個類庫的項目,命名為“FeatureToRunCode”,
將Class1.cs命名為MyCode.cs。添加引用Microsoft.sharepoint.dll。添加引用using Microsoft.SharePoint;并在MyCode類繼承SPFeatureReceiver。
整個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)//當激活時修改網站的標題為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)//當激活時修改網站的標題為首頁
??????? {
??????????? SPWeb web = (SPWeb)properties.Feature.Parent;
??????????? web.AllowUnsafeUpdates = true;
??????????? web.Title = "首頁";
??????????? web.Update();
??????????? web.Close();
??????? }
??????? public override void FeatureInstalled(SPFeatureReceiverProperties properties)//當Feature被安裝時,
??????? {
?????????? //當Feature被安裝時,執行代碼
??????? }
??????? public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
??????? {
????????? //當Feature被卸載時,執行代碼
??????? }
??? }
}
記得加入強名稱,編譯生成FeatureToRunCode.dll。并用Reflector.exe獲取
程序集名:FeatureToRunCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=146ae474b0fd2221
類名:FeatureToRunCode.MyCode
將在后面的feature.xml文件中被用到。
第二步:
開始創建Feature文件。在FeatureToRunCode項目中,創建文件夾Features,在文件夾Features目錄下創建文件夾FeatureToRunCode,在FeatureToRunCode文件夾下創建feature.xml.
feature.xml的代碼如下:
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
???????? Id="E46240B7-8050-47e7-8A12-586C291B346C"
???????? Title="FeatureToRunCode"
???????? Description="用feature管理運行后臺代碼"
???????? Hidden="FALSE"
???????? Scope="Web"
???????? ReceiverClass="FeatureToRunCode.MyCode"
???????? ReceiverAssembly="FeatureToRunCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=146ae474b0fd2221"
???????? >
</Feature>
說明:
在這個XML文件中,以下關于Featrue的metadata 包含在Featrue 元素中。(更詳細的信息請參閱Feature.xml Files)
ID: 一個GUID,用于唯一標識這個Feature,可以通過VS生成
Title:Feature 的名字,可以在網站內關于Site Featrues的頁面中看到。
Description:對description的描述。
Version:Feature的版本;
Scope:其值可以是Web或Site,它指明了這個Feature是應用于整個的Site Collection還是僅僅用于單獨的一個子站點。
Hidden:值可以是True或False.該設置指定了這個Feature是否在Site Feature頁面上顯示。
DefaultResourceFile: 資源文件名字,Feature依賴它提供其它附加的配置信息。
ReceiverClass:為程序集接收類。
ReceiverAssembly:為接收程序集.
保存。這樣我們的代碼跟Feature文件就已經創建好了,接下來就是布署了。
第三步:
布署Feature。先將FeatureToRunCode.dll拖入到GAC里,即c:\WINDOWS\assembly目錄下。
再到項目目錄下的Features目錄下,將FeatureToRunCode文件夾復制到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES目錄下。
在SharePoint服務器上打開命令行
輸入命令切換目錄:cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
安裝Feature輸入命令:stsadm -o installfeature -filename FeatureToRunCode\feature.xml。
不要忘了要iisreset一下服務器。
OK,Feature的部署與開發已經完成。
第四步:
查看成果。打開網站,進入網站設置,進入網站管理---->網站功能,可以看到增加了一個FeatureToRunCode的Feature功能,如下圖:
嗯,是不錯,趕緊點擊一下激活按鈕,有點激動,好在,代碼發揮作用了,網站的標題發生了變化了,變成My Feature is Working了,如下圖:
至此,Feature管理后臺代碼已經完成了!
*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>
?
轉載于:https://www.cnblogs.com/kasafuma/archive/2011/08/17/2141679.html
總結
以上是生活随笔為你收集整理的sharepoint站点Feature的定制与开发 以及 stsadm 常用命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IIS 应用程序池设置
- 下一篇: 利率加点幅度1.57%是什么意思