Getting Started with STSADM Extensions

Posted on Posted in Article

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.

4 thoughts on “Getting Started with STSADM Extensions

  1. Hi.
    Could you tell me how do I use these extensions of STSADM you created?
    I’m new at sharepoint’s world and I need to get all attachments from a document library of old wss and upload to the new web site!(wss 3.0).

    Hope you can help me.

    Thx anyway!

  2. If you’re trying to go from WSS v2 to v3 then my commands won’t really help you any. The easiest approach, if you don’t need any meta data, is to open each library in explorer view and then just drag and drop the files. Beyond that you’ll have to either write something custom or I’d recommend looking into Quest Software’s migration tools or something similar.

  3. Thanks for you reply.
    Unfortunately i think “drag-n-drop” wont help me. Because we developed a mini-system throught webpart using sharepoint lists, document library and another features as database and plataform for that system.
    Then each document library has a column that identifies the item from the record (another custom list) that is being viewed.
    And thats is the problem! I have to import a lot of attachments without losing that identification with the record of another list.

    I’ll keep trying to find another solution to resolve my problem, and i’ll check out this “Quest Software’s migration tools” that u told me!

    Thanks a lot for your attention. If u prefer my email is

    (by the way: i’m sorry by my english. I’m brazilian and just learning yet! =D)

  4. Hello i am running WSS 3.0
    all was working for a year or so and all the suden i can qury the users.aspx and setting.aspx
    I desperately need your help.
    I keep getting “ the file can not be found ”
    On settings.aspx
    pleae advice.

Leave a Reply

Your email address will not be published. Required fields are marked *