for example, stsadm -o back http://myportal" c:\bacl.bak , this operation used to take a backup.
if i need to display/delete all the Sites,subsites(sites under subsites), there is no direct command to get this functionality.
We can achive this functionality extending the stsadm operation.So i am going to write the operation as DisplaySites/DeleteSites, which means it will delete the sites/webs/sites under web.(Recursive).
My Stsadm tool will look like this
stsadm -o displaysites -url "http://myportal
There are two steps required to achieve this functonality
1.create a class which implements ISPStsadmCommand
2.Create a xml which has the public key token of class file and placed in (config folder : c:\program files\common file\microsoft shared\webserver extension\12 \config\
xmlfilename should be like this
stsadmcommands.customsitedelete.xml
Now will get into example
namespace CustomStsCommand.DisplaySites
{
public class DisplaySite : ISPStsadmCommand
{
#region ISPStsadmCommand Members
public string GetHelpMessage(string command)
{
return "-url
}
public int Run(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
{
SPSite site = null;
SPWeb web = null;
output = string.Empty;
if (keyValues.Count == 2)
{
if (keyValues["url"] == null)
{
output += "Not valid command parameter";
return 1;
}
try
{
site = new SPSite(keyValues["url"]);
web=site.OpenWeb();
if (web == null)
output = "Web not found";
else
{
if (site.Url == web.Url)// Check because Openweb returning top level site if url passed doesn't exist
{
return 1;
}
DisplayWebRecursive(web.Webs,output);
if (web.Url==keyValues["url"])
{
output = output + web.Title.ToString();
}
return 1;
}
}
catch (Exception ex)
{
output = ex.Message;
}
finally
{
if (site != null) site.Dispose();
if (web != null) web.Dispose();
}
}
else
{
output = "Invalid number of parameters or missing parameters";
}
return 1;
}
public string DisplayWebRecursive(SPWebCollection webs,string output)
{
foreach (SPWeb wb in webs)
{
if (wb.Webs.Count > 0)
{
DisplayWebRecursive(wb.Webs,output);
}
output = output + wb.Title.ToString() + "\r\n"; //wb.Title.ToString();
}
return output;
}
#endregion
}
}
and Xml file looks like this
Hope this example helps you to achieve the stsadm extended functionality



