MSDN官方参考 扩展 STSADM 实用工具
我这里做一个命令 格式大概是 stsadm -o subwebs -url
作用是列出SPSite下的所有SPWeb的Title,url是SPSite的url,
我们要做的也就是
(1)一个带签名的类库,
一个实现ISPStsadmCommand接口的类,
接口有两个方法
string GetHelpMessage(string command);
int Run(string command, StringDictionary keyValues, out string output);
(2)C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG
目录下新建一个 stsadmcommands.xxx.xml
xxx是你自己需要取的名字,不要和已经存在冲突
注册你的命令处理的程序集和类
你需要把dll文件放到gac
重启iis
我这里贴出我的代码
stsadmcommands.subwebs.xml
代码
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
commands
>
<
command name
=
"
subwebs
"
class
=
"
Portal.Lib.CustomCommands.SubWebsCommands, Portal.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=00cdd7799e190513
"
/>
</
commands
>
SubWebsCommands.cs文件
代码
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint.StsAdmin;
using
Microsoft.SharePoint;
using
System.Collections.Specialized;
namespace
Portal.Lib.CustomCommands
{
public
class
SubWebsCommands : ISPStsadmCommand
{
public
string
GetHelpMessage(
string
command)
{
return
"
-url <full url to a site in SharePoint>
"
; ;
}
public
int
Run(
string
command, StringDictionary keyValues,
out
string
output)
{
string
cmd
=
command.ToLowerInvariant();
switch
(cmd)
{
case
"
subwebs
"
:
return
this
.EnumerateSuWebs(keyValues,
out
output);
default
:
throw
new
InvalidOperationException();
}
}
private
int
EnumerateSuWebs(StringDictionary keyValues,
out
string
output)
{
if
(
!
keyValues.ContainsKey(
"
url
"
))
{
throw
new
InvalidOperationException(
"
The url parameter was not specified.
"
);
}
String url
=
keyValues[
"
url
"
];
SPSite site
=
null
;
StringBuilder sb
=
new
StringBuilder();
try
{
site
=
new
SPSite(url);
SPWebCollection webCol
=
site.AllWebs;
for
(
int
i
=
0
; i
<
webCol.Count; i
++
)
{
using
(SPWeb web
=
webCol[i])
{
sb.AppendLine(web.Title);
}
}
}
catch
(Exception ex)
{
throw
new
InvalidOperationException(ex.Message);
}
finally
{
if
(site
!=
null
)
{
site.Dispose();
}
}
output
=
sb.ToString();
return
0
;
}
}
}
后话:
其实这样作用并不是很大,完全可以做到完全可视化的操作,不是么