Microsoft.SharePoint.StsAdmin.ISPStsadmCommand interface.
The actual process involves two steps.
- Creating the configuration xml file.
- Creating a class that implements ISPStsadmCommand interface.
The configuration xml file indicates to stsadm.exe which operations are available. This configuration file must follow well known naming convention stsadmcommands.<customcommands>.xml where <customcommands> can be any meaningful name but must be unique. Through this naming convention for configuration files, stsadm.exe implements a pluggable architecture for declaring custom operations.
<?xml version="1.0" encoding="utf-8"?>
<commands>
<command name="<name for command>" class="<namespace>,<class>,Version=<version>,
Culture=neutral,PublicKeyToken=<token>">
</command>
</commands>
The configuration file itself is a simple XML document with a
.Net assembly
The .Net assembly containing the classes has to be placed in GAC. Each operation requires separate class inheriting ISPStsadmCommand interface. The ISPStsadmCommand interface has two methods to implement.
1. GetHelpMessage – this method returns help and usage information.
2. Run – this method actually does the custom operation.
class CustomActivateFeature : ISPStsadmCommand
{
//method to return help message
public string GetHelpMessage(string command)
{
//named parameters expected
return "-url
}
//method called to perform the action
public int Run(string command,
System.Collections.Specialized.StringDictionary keyValues,
out string output)
{
//assign value to variables
if (keyValues.ContainsKey("url"))
{
url = keyValues["url"];
if ((url == null) (url.Length == 0)) output += "url cannot be empty";
:
:
Deployment
The deployment process involves two steps.
1. Copy the configuration file (stsadmcommands.feature.xml) to [12 Hive]\CONFIG folder.
2. Copy the DLL file to GAC.
Now we can perform our custom actions using stsadm.exe by typing
stsadm.exe –o <name we have specified in xml file> <named
parameters> at command prompt.
It can be very useful to include in script/batch file for actions like backup, restore or some other automated actions.
No comments:
Post a Comment