Archive | September 2010

WSS V 3.0 provides option for us to extend the stsadm commands and customize the operations as per our requirements .
I have extended stsadm to one such command that list outs the list and libraries for a specified sharepoint site .

Namespaces used : Microsoft .Sharepoint and Microsoft.Sharepoint.StsAdmin

The process involves 4 steps as mentioned below :
1.Create a class library project with custom class extending the ISPStadmCommand Interface . Enclosed is the code and comments are inline
namespace ExtendStsadm
{
public class CustomStsadm :ISPStsadmCommand
{
//Get help on the extended command
//execute stsadm -o enumlist to get help

public string GetHelpMessage(string command)
{
return “-url “;
}

//Run() executes the command extended
public int Run(string command, StringDictionary keyValues, out string output)
{
command = command.ToLower();
switch (command)
{
case “enumlist”: return this.EnumLists(keyValues,out output);
default: throw new InvalidOperationException();
}
}

public int EnumLists(StringDictionary keyValues ,out string output)
{
if (!keyValues.ContainsKey(“url”))
{ throw new InvalidOperationException(“The url parameter was not specified.”);
}
String url = keyValues[“url”];
SPSite oSite = null;
SPWeb oWeb = null;
StringBuilder oStringBuilder = new StringBuilder();
//loop through the site to list out the List /libraries for it
try
{
oSite = new SPSite(url);
oWeb = oSite.OpenWeb();
SPListCollection oListColl=oWeb.Lists;
foreach (SPList oList in oListColl)
{
oStringBuilder.AppendLine(oList.Title.ToString());
}
output = oStringBuilder.ToString();
}
catch (Exception ex)
{ throw new InvalidOperationException(ex.Message.ToString());
}
return 0;
} }}

2.String name the assembly ,build the project ,move it to GAC and do an iisreset .
3.Now ,we need to add a configuration entry for registering class and assembly defined.
Go to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG ,Create an xml
file to hold this configuration and name it as stsadmcommands.[ClassName].xml and add the config entry
enclosed and save the file:
4.Execute the command
stsadm -o enumlist -url [url of the sharepoint site]
Now , we should be able to enumerate the list/libraries for a specified sharepoint site.