Before I talk about the commands that I’ve created I wanted to spend a moment to show how I’ve approached the creation of the commands. If you’re faced with a situation like mine where you have to automate numerous MOSS configurations then you basically have two options – the first is to use STSADM (and possibly custom extensions) and the third is to just write your own console or WinForm app and plug away against the API.
The reason I chose to use STSADM and custom extensions was so that I wouldn’t have to recompile every time I needed to add an additional step and so that I could re-use the commands after we roll out. To get started creating your own extensions the first thing you’ll need is a SharePoint environment in which you can test your code. If you use Windows Server 2003 as your development platform then you can simply install and configure SharePoint locally. Otherwise you’ll have to do what I did which is to create a virtual PC. My virtual PC has Windows Server 2003 R2 with Reflector, Office 2007, Visual Studio 2005, SQL Server 2005, and of course SharePoint 2007.
I also have another virtual PC which I use to test the gradual upgrade – so my dev VPC is for where I can create, test, break, fix, etc. – once I’m comfortable I move my built code to my upgrade test VPC where I’m scripting out every change using a simple batch file with calls to STSADM. Once your environment is setup the first thing you need to do before creating an extension is make sure that what you need to accomplish can’t already be done with the out-of-the-box STSADM.
This may sound obvious but it’s more challenging than you may thing – some of the commands are not exactly named clearly and it’s easy to miss one when you’re scanning through them (especially if you’ve installed other add-ons like Project Server which adds it’s own set of extensions). More than once I’ve found myself beginning the process of creating a command that I though didn’t exist only to discover it was already there later when looking for something else. Once I know I’m stuck creating my own then I would open SharePoint to the page which would allow me to change the configuration via the web interface. For example, the first command I created was one which would allow me to create a quota template (STSADM allows you to set a default quota template to a web application but does not allow you to create one).
So I went to the Quota Templates page in Central Admin (http://yourcaserver/_admin/ManageQuotaTemplate.aspx
) to see what kind of information the web site was asking for. The next thing you need to do is either dig through the SDK and try to find the right object to accomplish the task (good luck with that) or see how Microsoft is doing it by disassembling the web page. To disassemble the web page you can either go to the 12 hive where the pages are stored (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN
for CA pages), find the right aspx file and look at the Inherits attribute of the @Page tag or you can find the JIT compiled page in your temp folder (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\
) and then drag the dll into Reflector and navigate to the base class.
In either case where you want to get is the base class which in this case is Microsoft.SharePoint.ApplicationPages.ManageQuotaTemplatePage
. You can find the assembly for this class here: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG\ADMINBIN\Microsoft.SharePoint.ApplicationPages.Administration.dll
. Some of the assemblies you’ll end up needing are also in the ISAPI folder or the BIN folder (you’ll just have to search – some are also only in the GAC so you’ll have to go to the command line and manually copy them out to a temp folder so you can disassemble them). Once I’ve got the page in Reflector then it becomes a simple matter to dig through the code to find what Microsoft is doing.
You’ll find in many cases Microsoft is using internal helper classes to do the work so you may have to dig through several levels to figure out how you can do it using classes available to you. In this case you can see fairly quickly that they are using the SPQuotaTemplate
class and the SPQuotaTemplateCollection
class to manage quotas (this isn’t the best example as a quick search in the SDK for “quota” would reveal this information but it demonstrates what you’ll have to do most of the time and also allows you to see how Microsoft is handling things such as translation from megabytes to bytes and what other error handling may be involved, among other things).
Now that you have this information you can start creating your extension. My follow on posts will discuss each of the commands I’ve created, why I needed them, and what some of the challenges were in creating them. For more information about creating the XML file and the project structure see Joerg’s posting on Code Project or Tony’s article on Zimbio.